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
Claudio Bley wrote:
> >>>>> "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
Hmm,
... and this was a typo. Sorry.
Frank
begin:vcard
n:Schafer;Frank
x-mozilla-html:FALSE
org:SETUZA a.s.;IT
adr:;;;;;;
version:2.1
email;internet:frank.schafer@setuza.cz
title:Dipl. Ing.
note:System administrator
x-mozilla-cpt:;0
fn:Frank Schafer
end:vcard