使用包含另一个静态库的静态库时,LNK4006,LNK4221警告 [英] LNK4006, LNK4221 warnings when using static library that includes another static library

查看:487
本文介绍了使用包含另一个静态库的静态库时,LNK4006,LNK4221警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use static library that include other static libraries.

有两个项目:Engine,MyGame

There are two projects: Engine, MyGame

引擎"将产生Engine.lib

'Engine' is going to produce Engine.lib

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

'MyGame' is going to use Engine.lib when it is linking.

以下是我从Visual Studio 2012获得的构建消息:

Following is the build message that I'm getting from 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 ==========

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

At first, it seems like 'MyGame' fails to find Engine.lib, but the project does produce executable that runs fine.

第二,引擎"包括其他库(SDL2,OpenGL,GLEW)以产生其新库,但它表示符号重复.

Second, 'Engine' includes other libraries(SDL2, OpenGL, GLEW) to produce its new library, but it says symbols are duplicated.

  1. 符号"的确切含义是什么?

  1. What does 'symbol' exactly mean?

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

What does it mean symbol being 'public' when linking?

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

If these warnings are critical, why is it and how do I fix it?

如何配置项目之间的构建顺序?

How do I configure build sequence between projects?

在我的项目中是否有使用外部库的最佳实践?

Any best practices using external libraries in my project?

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

Two projects shares some dll(SDL2.dll, glew.dll). If other users are going to use this Engine.lib, how do I provide these dlls?

谢谢.

推荐答案

以逻辑(非顺序)顺序的一些答案:

Some answers, in logical (not sequential) order:

  • 重新:4 :MyGame必须包括对Engine的引用.这将迫使MyGame仅在Engine完成后才开始构建,并避免出现错误.请注意,仍然可以使用一种用于强制执行构建顺序的较旧的设备(项目依赖项"),但是今天您需要一个特殊的理由来使用它.

  • re: 4: MyGame must include a reference to Engine. This, among others, will force MyGame to start building only after Engine had finished and avoid the error you're getting. Note that one older apparatus for forcing build order is still respected ('project dependencies'), but you'd need an exceptional reason to use it today.

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

re 1: A symbol in this context is an 'atom' of linker work. It is either a function or a global variable, that can be consumed in multiple translation units.

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

re 3: These warnings are not critical. LNK4006 here ultimately comes from static libs including reference to other static libs (which is allowed but not encouraged by MS). The LNK4221 is most probably misuse of wizard-generated precompiled header files

re 6 :原则上,安装程序必须安装您使用的任何第三方组件,并将它们连接起来,以便您的二进制文件可以找到它们(注册表项,环境变量等). SDL2可能就是这种情况(?),但是OpenGL在Windows附带的事实-因此,除非您使用的是其他版本,否则应该没问题.

re 6: In principle your installer must install any 3rd party components you consume, and wire them up so your binaries find them (registry keys, environment variables, whatever). That is probably the case for SDL2 (is that it?), but OpenGL is in fact shipped with windows - so unless you're using some exotic version you should be ok.

这篇关于使用包含另一个静态库的静态库时,LNK4006,LNK4221警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆