windows 为什么我会在使用其他库时遇到 LNK4098 冲突 - 在 MSVS2010 Express 中尝试编译 C++ 时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5839362/
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
Why do I get LNK4098 conflicts with use of other libs - when trying to compile C++ in MSVS2010 Express?
提问by William Whispell
My program will not successfully compile in /MT (MultiThreaded) mode. It Compiles in /MD (MultiThreaded DLL). I want to be able to use both libcurl and boost in an application I will distribute with an installer.
我的程序无法在 /MT(多线程)模式下成功编译。它在 /MD(多线程 DLL)中编译。我希望能够在我将通过安装程序分发的应用程序中同时使用 libcurl 和 boost。
Compiling in: MSVS2010
编译在:MSVS2010
This is code to replicate my problem:
这是复制我的问题的代码:
#include "stdafx.h"
#include "boost/regex.hpp"
#include "curl/curl.h"
int _tmain(int argc, _TCHAR* argv[])
{
CURL *curl;
curl = curl_easy_init();
return 0;
}
This is the warning I get if in /MD mode:
这是我在 /MD 模式下收到的警告:
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs;
use /NODEFAULTLIB:library
If I try compiling in /MT mode I get:
如果我尝试在 /MT 模式下编译,我会得到:
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _calloc already defined in
LIBCMT.lib(calloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _realloc already defined in LIBCMT.lib(realloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _strtoul already defined in LIBCMT.lib(strtol.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _memmove already defined in LIBCMT.lib(memmove.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _tolower already defined in LIBCMT.lib(tolower.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _strtol already defined in LIBCMT.lib(strtol.obj)
...
: fatal error LNK1169: one or more multiply defined symbols found
I want to compile in /MT mode so that others can run my finished program with out having MSVS installed or needing to download anything additional. I can include and dll or lib files needed by my app in the installer.
我想在 /MT 模式下编译,以便其他人可以运行我完成的程序,而无需安装 MSVS 或需要下载任何其他内容。我可以在安装程序中包含我的应用程序所需的 dll 或 lib 文件。
I could disable loading the 'MSVCRTD' default library, but then compiling the with boost fails.
我可以禁用加载“MSVCRTD”默认库,但随后编译 with boost 失败。
These are my preprocessor definitions:
这些是我的预处理器定义:
WIN32
_DEBUG
_CONSOLE
BUILDING_LIBCURL
HTTP_ONLY
These are my additional dependencies:
这些是我的附加依赖项:
libcurl.lib
ws2_32.lib
winmm.lib
wldap32.lib
Does anyone know what I am doing wrong?
有谁知道我做错了什么?
Thanks, William
谢谢,威廉
回答by Eric Z
Try setting nodefaultlib:libcmt.lib
in linker options in VC.
尝试nodefaultlib:libcmt.lib
在 VC 中的链接器选项中设置。
回答by holydel
MSVCRT*D* LIBC*MT*.lib
MSVCRT* D* LIBC* MT*.lib
flag compile the library differs from the flag compile the project (/MT,/MTD,/MD,/MDD)
flag compile the library 不同于 flag compile the project (/MT,/MTD,/MD,/MDD)
回答by Alexey Ivanov
Try to remove _DEBUG
from precompiler directives (i.e. build release version). The libraries you link into your application use a non-debug versions and your code links to debug-version. That's why you get linker error that symbols are multiply defined: it links both debug and non-debug versions of runtime libraries.
尝试_DEBUG
从预编译器指令中删除(即构建发布版本)。您链接到应用程序的库使用非调试版本,而您的代码链接到调试版本。这就是为什么您会收到符号被多重定义的链接器错误的原因:它链接了运行时库的调试版本和非调试版本。
(As far as I understood you tried to statically link all the required libraries.)
(据我所知,您尝试静态链接所有必需的库。)
回答by munsingh
Try building libCurl with rtlibcfg=static. This will build the /Mt static version of libCURL.
尝试使用 rtlibcfg=static 构建 libCurl。这将构建 libCURL 的 /Mt 静态版本。