Re: Multiple difinitions of global variables

Discussion in 'C++' started by Erik, Aug 21, 2003.

  1. Erik

    Erik Guest

    > 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
    Erik, Aug 21, 2003
    #1
    1. Advertising

  2. Erik

    Erik Guest

    "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
    >
    >
    Erik, Aug 21, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wayne
    Replies:
    2
    Views:
    469
    Wayne
    Nov 11, 2003
  2. Jack Klein
    Replies:
    0
    Views:
    385
    Jack Klein
    Aug 21, 2003
  3. jubelbrus
    Replies:
    5
    Views:
    615
    JohnQ
    Jul 20, 2007
  4. mark4asp
    Replies:
    1
    Views:
    216
  5. Tony Archer

    Global Variables? Multi-Application Variables?

    Tony Archer, Nov 24, 2003, in forum: ASP General
    Replies:
    5
    Views:
    222
    Tony Archer
    Nov 25, 2003
Loading...

Share This Page