This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Porting from Solaris to Linux problem
- To: frank dot schafer at setuza dot cz
- Subject: Re: Porting from Solaris to Linux problem
- From: bley at wh2-19 dot st dot uni-magdeburg dot de (Claudio Bley)
- Date: Tue, 6 Nov 2001 14:39:50 +0100
- Cc: Frank Geck <fgeck at att dot net>, GCC help <gcc-help at gcc dot gnu dot org>
- References: <3BE6BEA1.2ED3509E@att.net><3BE78B4F.F7BF145A@setuza.cz>
>>>>> "Frank" == Frank Schafer <frank.schafer@setuza.cz> writes:
Frank> Frank Geck wrote:
>> Well I have run into a little problem porting some code from
>> Solaris to Linux. I think I know what the problem is and I can
>> think of a lame way to fix it but wanted to know what was the
>> right way (maybe on Solaris I had been doing it wrong all these
>> years). I have 2 files each containing a function and a common
>> header file with a global variable. In each file I include the
>> header file and mark the global as external. In solaris this
>> works fine using gcc, in Linux it gives me multi-defined. Any
>> thought would be appreciated.
>>
>> Exmple:
>>
>> file: hdr.h int i;
>>
>> file: main.c #include "hdr.h" extern int i; main() { ... }
>>
>> file: func2.c #include "hdr.h" extern int i; func2() { ... }
Frank> Hi,
Frank> I'd make the following changes:
Frank> file: hdr.h #ifndef HDR_H #define HDR_H 1
Frank> extern int i;
Frank> #endif /* HDR_H */
Frank> file: main.c #include "hdr.h"
Frank> main() { ... }
Frank> file: func2.c #include "hdr.h"
Frank> func2() { ... }
Frank> This should solve Your problem.
Not quite. `i' has to be defined somewhere, it is not sufficient to
declare it extern.
file: hdr.c
==========
#include "hdr.h"
int i;
==========
HTH
Claudio