Re: More projects in a C++ solution: how to link them together?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 12/16/04

  • Next message: Peter Koch Larsen: "Re: real numbers"
    Date: Thu, 16 Dec 2004 15:16:53 -0500
    
    

    Agoston Bejo wrote:
    > I have two projects, one depending on another. In the first a global
    > variable is defined:
    > x.hpp:
    > extern int x;
    > x.cpp:
    > int x = 5;
    >
    > When in the second project I try to use this global variable, I get a linker
    > error:
    > [...].obj : error LNK2001: unresolved external symbol
    >
    > How do I tell the linker to also use the object files from the first
    > project? Or is it such that global variables are only "project-global" but
    > cannot be made "solution-global"?

    Global variables are "target-global". I.e. their 'globality' is limited
    by the bounds of the result of linking.

    I presume at least one of your projects is a DLL (the one with the global
    object 'x'). You need to add the .lib file that is built as a result of
    linking that project to the other project's library list.

    V


  • Next message: Peter Koch Larsen: "Re: real numbers"

    Relevant Pages

    • Re: More projects in a C++ solution: how to link them together?
      ... > extern int x; ... > When in the second project I try to use this global variable, I get a linker ... > How do I tell the linker to also use the object files from the first ... linking that project to the other project's library list. ...
      (microsoft.public.vsnet.ide)
    • Re: rtld + static linking
      ... > shared libraries do. ... for the current implementation of the linker. ... and made no changes to the constructor argument ... the same source file is use for both dynamic and static linking. ...
      (freebsd-current)
    • Re: Linker errors
      ... I would like to continue using incremental linking with the ... > The lead for the linker team looked at the dump info you provided and we ... > currently working on that addresses an issue when new imports get added ... > that mainly hits when we are linking very large images like in your case. ...
      (microsoft.public.dotnet.languages.vc)
    • How a linker works (continued)
      ... Some people insisted that I was generalizing too much and there could be C implementations without object files and C implementations that do not link files in separate compilation but just parse and digest each module, making the whole code generation step in the linker, from an unknown representation. ... Here I am speaking about the very common where the compiler produces traditional object files, ... and two types of relocations for the debug information, ...
      (comp.lang.c)
    • Re: extern variable
      ... the linker is from another GNU package ... GNU doc, ... actually invoked under) gcc marks items in the object files as ... AFAIK GNU ld always does this for common, ...
      (comp.lang.c)