Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Multiple difinitions of global variables

Reply
Thread Tools

Re: Multiple difinitions of global variables

 
 
Erik
Guest
Posts: n/a
 
      08-21-2003
> 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;

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.
</OT>

/ Erik


 
Reply With Quote
 
 
 
 
Erik
Guest
Posts: n/a
 
      08-21-2003

"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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialize global variable before any other global variables jubelbrus C++ 5 07-20-2007 06:38 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Global variables on par with ASP's global.asa Wayne ASP .Net 2 11-11-2003 10:58 PM
Re: Multiple difinitions of global variables Jack Klein C++ 0 08-21-2003 02:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57