C++ “LIBCMT”与其他库的使用冲突 + 未解析的外部符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14148933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'LIBCMT' conflicts with use of other libs + unresolved external symbols
提问by Andrew
I have a program using OpenGL 3.2(+libs) and FreeType2. Then an other program with Boost and OpenSSL. The OpenGL side was to make sure text could be rendered and the boost/openssl program is to do a secure login/game server.
我有一个使用 OpenGL 3.2(+libs) 和 FreeType2 的程序。然后是另一个带有 Boost 和 OpenSSL 的程序。OpenGL 方面是确保可以呈现文本,而 boost/openssl 程序是做一个安全的登录/游戏服务器。
Both programs work fine by them selfs.
这两个程序都可以由他们自己正常工作。
However adding Boost and OpenSSL to the game(GL + freetype) project caused it to fail to link.
但是,将 Boost 和 OpenSSL 添加到游戏(GL + freetype)项目会导致无法链接。
I have linked the following libs as well as including there includes folder.
我已经链接了以下库以及包含文件夹。
glimg.lib glutil.lib glfw.lib opengl32.lib freetype.lib glew32.lib user32.lib libeay32.lib ssleay32.lib
glimg.lib glutil.lib glfw.lib opengl32.lib freetype.lib glew32.lib user32.lib libeay32.lib ssleay32.lib
The linker error is.
链接器错误是。
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libeay32.lib(cryptlib.obj) : error LNK2001: unresolved external symbol __imp__DeregisterEventSource@4
1>libeay32.lib(cryptlib.obj) : error LNK2001: unresolved external symbol __imp__ReportEventA@36
1>libeay32.lib(cryptlib.obj) : error LNK2001: unresolved external symbol __imp__RegisterEventSourceA@8
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__DeleteDC@4
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__DeleteObject@4
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__GetBitmapBits@12
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__BitBlt@36
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__GetObjectA@12
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__SelectObject@8
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__CreateCompatibleBitmap@12
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__GetDeviceCaps@8
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__CreateCompatibleDC@4
1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol __imp__CreateDCA@16
1>.\BasicTexture.exe : fatal error LNK1120: 13 unresolved externals
Runtime Library is set to Multi-threaded DLL (/MD)
运行时库设置为多线程 DLL (/MD)
I have no idea what to do I would really appreciate any help.
我不知道该怎么做,我真的很感激任何帮助。
回答by Adrian McCarthy
You are trying to compile with /MD
, which is probably the right choice, but some code (probably one of the libraries) was built with /MT
, and you can't have it both ways in the same program. You need to figure out which library was built with /MT
and rebuild it with /MD
.
您正在尝试使用 编译/MD
,这可能是正确的选择,但是某些代码(可能是库之一)是使用 构建的/MT
,并且您不能在同一个程序中同时使用它。您需要确定使用哪个库构建/MT
并使用/MD
.
回答by IInspectable
Unresolved external error messages are produced when the compiler generates code referencing externally defined objects or functions and the linker fails to find those. To generate code invoking a function call the compiler only needs a declaration:
当编译器生成引用外部定义的对象或函数的代码而链接器未能找到它们时,会产生未解决的外部错误消息。要生成调用函数调用的代码,编译器只需要一个声明:
extern "C" BOOL DeregisterEventSource ( HANDLE hEventLog );
This is enough information to produce a call
instruction (except for the target address). The extern
keyword informs the compiler that the implementation is defined elsewhere. Consequently it cannot know the target address which has to be filled in later. When the compiler is done it is the linker's job to connect the pieces together. It uses the information gathered from the import libraries to look up the required offsets.
这足以产生一条call
指令(目标地址除外)。该extern
关键字通知编译器该实现是在别处定义的。因此它无法知道稍后必须填写的目标地址。编译器完成后,链接器的工作是将各个部分连接在一起。它使用从导入库收集的信息来查找所需的偏移量。
Windows API calls are easily spotted in the error log. They have an __imp__
prefix and sometimes an A
or W
postfix followed by @<n>
where <n>indicates the number of bytes required for the arguments. In the case of a Windows API call you can then look up the function in the MSDN (like DeregisterEventSource). Towards the bottom are the Requirementswhere you can find the import library name.
Windows API 调用很容易在错误日志中发现。它们有一个__imp__
前缀,有时还有一个A
或W
后缀,@<n>
其中<n>表示参数所需的字节数。在 Windows API 调用的情况下,您可以在 MSDN 中查找该函数(如DeregisterEventSource)。底部是要求,您可以在其中找到导入库名称。
The conflict warning indicates that not all of the modules use the same runtime library. Even though this is just a warning it is a serious issue and should be resolved. You get this warning if you mix /MD
and /MT
compiler switches, but also, if you mix release and debug runtime libraries (like /MD
and /MDd
). To diagnose this message you can use the /VERBOSE:LIB
linker switch to determine which libraries the linker is searching. Additional information on this warning can be found at this MSDN link.
冲突警告表明并非所有模块都使用相同的运行时库。尽管这只是一个警告,但它是一个严重的问题,应该解决。如果混合使用/MD
和/MT
编译器开关,也会收到此警告,如果混合使用发布和调试运行时库(如/MD
和/MDd
)。要诊断此消息,您可以使用/VERBOSE:LIB
链接器开关来确定链接器正在搜索哪些库。可以在此MSDN 链接中找到有关此警告的其他信息。