[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] (no subject)

From: MuRaT KaRaDeNiZ
Subject: RE: [avr-gcc-list] (no subject)
Date: Mon, 30 Jan 2006 23:03:05 +0200

Hi Dave,

My header looks like this:

#ifndef GLOBAL_H
#define GLOBAL_H

u08 tx_packet_length=0;
u08 header_ok=0;
u08 RX485_oldbyte3, RX485_oldbyte2, RX485_oldbyte1;


I wait from conditional definition, that it  protects from multiple
definitions, and if I include the header, no extern should be needed,

u08 RX485_oldbyte3, RX485_oldbyte2, RX485_oldbyte1; //does not cause any

u08 tx_packet_length=0;
u08 header_ok=0;                //gives multiple definition error , when
header is included in multiple  project files

My problem is still unanswered, what is this?

Best Regards

Murat Karadeniz

-----Original Message-----
From: Dave Hylands [mailto:address@hidden 
Sent: Monday, January 30, 2006 9:30 PM
To: MuRaT KaRaDeNiZ
Cc: AVR-GCC-list
Subject: Re: [avr-gcc-list] (no subject)


Sending to list...

> I live a problem with avr gcc: When i use a global variable in the 
> header file and simultaneously initialize it to nonzero value in the 
> declaration, then the use of this header file in multiple project 
> source files as an include causes "multiple definition error" on this 
> specific lines in the header file. Not initialized globals (by myself)

> and defines do not cause any error.  the whole header file content  is

> in a conditional define, in a regular manner, so  i dont understand 
> what is going on. what is wrong?

In the header file, you need to use the word extern.


   int x;

says to allocate storage for an int sized variable named x. Since this
is in a header file, every C file that includes the header file will try
to create a variable named x, which is where the multiple declarations
are coming from.


   extern int x;

says that somebody else has allocated storage for an int sized variable
named x.

Dave Hylands
Vancouver, BC, Canada

reply via email to

[Prev in Thread] Current Thread [Next in Thread]