"Erik" <> wrote in message news:bi2tkf$1bn$...
> > I am working on a project to port some C++ code from UNIX to Windows and
> > having some problems to get them built on windows. One problem is about
> the
> > multiple difinitions of global variables. In UNIX, most compilers
support
> > the multiple difinitions.
> > While on windows, I got the following errors from Visual C++ 6.0:
> > HeaderA.obj : error LNK2005: "int length" (?length@@3HA) already defined
> in
> > vctest.obj
> > Debug/AnotherVCTest.exe : fatal error LNK1169: one or more multiply
> defined
> > symbols found
> > Error executing link.exe.
> >
> > Can anyone tell me how to get around this problem?
> > Code:
> > file HeaderA.h:
> > #ifndef _HEADER_A
> > #define _HEADER_A
> >
> > int length;
>
> <OT>
> __declspec(selectany) int length;
Sorry, must be __declspec(selectany) int length = 0;
> Although this is possible, I recommend you to use the solution suggested
by
> the other
> posters if you don't have a very good reason for not doing it.
Comment remains.
> </OT>
>
> / Erik
>
>
|