Link libraries with dependencies in Visual C++ without getting LNK4006

后端 未结 9 1941
难免孤独
难免孤独 2020-12-16 10:56

I have a set of statically-compiled libraries, with fairly deep-running dependencies between the libraries. For example, the executable X uses libraries A and B, A uses libr

相关标签:
9条回答
  • 2020-12-16 11:35

    Poor flodin seems frustrated that nobody will explain how to disable the linker warnings. Well, I've had a similar problem, and for years I have simply lived with the fact that several hundred warnings were displayed. Now, however, thanks to the info from Link /ignore, I figured out how to disable the linker warnings.

    I'm using Visual Studio 2008. In Project -> Settings -> Configuration Properties -> Librarian -> Command Line -> Additional Options, I added "/ignore:4006" (without the quotes). Now my warnings are gone!

    0 讨论(0)
  • 2020-12-16 11:45

    I think the best course of action here will be to ignore/disable the linker warnings(LNK4006) since C.lib needs to be part of both A.Lib and B.lib and A.Lib does not need to know that B.lib itself uses C.Lib.

    0 讨论(0)
  • 2020-12-16 11:48

    The problem is you are not localizing library C's symbols. So you have a ODR violation when you link in A and B. You need to have a way to make these private. By default all symbols are exported. One way to do this is to have a special linker definition file for both A and B that explicitly mention which files need to be exported.

    [1] ODR = One Definition Rule.

    0 讨论(0)
提交回复
热议问题