LNK4006,LNK4221在使用包含另一个静态库的静态库时发出警告

use*_*715 6 c++ dll linker static-libraries visual-studio-2012

我正在尝试使用包含其他静态库的静态库.

有两个项目:Engine,MyGame

'Engine'将生成Engine.lib

'MyGame'将在链接时使用Engine.lib.

以下是我从visual studio 2012获得的构建消息:

1>------ Rebuild All started: Project: Engine, Configuration: Debug Win32 ------
2>------ Rebuild All started: Project: MyGame, Configuration: Debug Win32 ------
1>  Precompiled.cpp
2>  Main.cpp
2>LINK : fatal error LNK1104: cannot open file 'D:\klee\Engine\Debug\Engine.lib'
1>  RenderGame.cpp
1>  RenderDebug.cpp
1>  MsgHandler.cpp
1>  Main.cpp
1>  Log.cpp
1>  Input.cpp
1>  Interface.cpp
1>  Helper.cpp
1>  GameObject.cpp
1>  Framework.cpp
1>  Engine.cpp
1>  Config.cpp
1>  Component.cpp
1>  Generating Code...
1>  Guicon.cpp
1>glu32.lib(GLU32.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in glew32.lib(glew32.dll); second definition ignored
1>glu32.lib(GLU32.dll) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
1>opengl32.lib(OPENGL32.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in glew32.lib(glew32.dll); second definition ignored
1>opengl32.lib(OPENGL32.dll) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
1>SDL2.lib(SDL2.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in glew32.lib(glew32.dll); second definition ignored
1>SDL2.lib(SDL2.dll) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
1>  Engine.vcxproj -> D:\klee\Engine\Debug\Engine.lib
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)

起初,似乎'MyGame'无法找到Engine.lib,但该项目确实生成了运行正常的可执行文件.

其次,"引擎"包括其他库(SDL2,OpenGL,GLEW)来生成其新库,但它表示符号是重复的.

  1. "符号"究竟意味着什么?

  2. 链接时符号被"公开"是什么意思?

  3. 如果这些警告很重要,为什么会这样,我该如何解决?

  4. 如何在项目之间配置构建顺序?

  5. 在我的项目中使用外部库的任何最佳实践?

  6. 两个项目共享一些DLL(SDL2.dll,glew.dll).如果其他用户打算使用此Engine.lib,我该如何提供这些dll?

谢谢.

Ofe*_*lon 5

一些答案,按逻辑(非顺序)顺序:

  • 回复:4:MyGame 必须包含对引擎的引用。除其他外,这将强制 MyGame 仅在 Engine 完成后才开始构建并避免您遇到的错误。请注意,一种用于强制构建顺序的旧设备仍然受到尊重(“项目依赖性”),但您今天需要一个特殊的理由来使用它。

  • re 1:此上下文中的符号是链接器工作的“原子”。它是一个函数或一个全局变量,可以在多个翻译单元中使用。

  • re 3:这些警告并不重要。这里的 LNK4006 最终来自静态库,包括对其他静态库的引用(MS 允许但不鼓励)。LNK4221 很可能是误用了向导生成的预编译头文件

  • re 6:原则上,您的安装程序必须安装您使用的任何 3rd 方组件,并将它们连接起来,以便您的二进制文件找到它们(注册表项、环境变量等)。SDL2 可能就是这种情况(吗?),但实际上 OpenGL 是随 Windows 一起提供的 - 所以除非您使用的是一些异国情调的版本,否则您应该没问题。

  • 没想到会得到这个问题的答案,因为已经一年了......但是谢谢! (2认同)