简体   繁体   English

静态库 (/MT) 链接与项目 /MTd 选项冲突

[英]Static library (/MT) linking conflicts with project /MTd option

My project links a lot of static libraries.我的项目链接了很多静态库。 All of them previously links well, but now I added mysql c api library and now I gets errors like that:所有这些以前链接都很好,但现在我添加了 mysql c api 库,现在我收到了这样的错误:

mysqlclient.lib(client_authentication.obj) : error LNK2038: mismatch detected for "_ITERATOR_DEBUG_LEVEL": value "0" doesn't match value "2" in mysql_database_connection.obj mysqlclient.lib(client_authentication.obj):错误 LNK2038:检测到“_ITERATOR_DEBUG_LEVEL”不匹配:值“0”与 mysql_database_connection.obj 中的值“2”不匹配
mysqlclient.lib(client_authentication.obj) : error LNK2038: mismatch detected for "RuntimeLibrary": value "MT_StaticRelease" doesn't match value "MTd_StaticDebug" in mysql_database_connection.obj mysqlclient.lib(client_authentication.obj):错误 LNK2038:检测到“RuntimeLibrary”不匹配:值“MT_StaticRelease”与 mysql_database_connection.obj 中的值“MTd_StaticDebug”不匹配

But only if I builds project with MTd option of MSVC runtime library (I using this runtime library option for development).但前提是我使用 MSVC 运行时库的 MTd 选项构建项目(我使用此运行时库选项进行开发)。 Other static libraries links well.其他静态库链接良好。 I can fix errors through changing MTd to MT, but I want to use MTd.我可以通过将 MTd 更改为 MT 来修复错误,但我想使用 MTd。 Why other static libraries links ok?为什么其他静态库链接正常? Compile options was same (libraries compiled by myself), MT option for all libraries, but only mysql c api can't be linked with my project MTd option.编译选项相同(我自己编译的库),所有库的 MT 选项,但只有 mysql c api 无法与我的项目 MTd 选项链接。 Why?为什么?
Thanks in advance!提前致谢!

The error indicates a conflict between the CRT libraries used in your project ( /MTd multithread static debug) and the ones used by the statically linked library ( /MT multithread static release).该错误表明项目中使用的 CRT 库( /MTd多线程静态调试)与静态链接库使用的 CRT 库( /MT多线程静态发布)之间存在冲突。 This is an error condition because one module (EXE or DLL) can only have/use one copy of the CRT.这是一种错误情况,因为一个模块(EXE 或 DLL)只能拥有/使用 CRT 的一个副本。

From the /MD, /MT, /LD (Use Run-Time Library) notes:来自/MD, /MT, /LD (Use Run-Time Library)注释:

All modules passed to a given invocation of the linker must have been compiled with the same run-time library compiler option传递给给定链接器调用的所有模块都必须使用相同的运行时库编译器选项进行编译

To fix the error, either build the project with /MT (release configuration), or rebuild the static library with /MTd (debug configuration) and link to that debug library, instead.要修复错误,请使用/MT (发布配置)构建项目,或者使用/MTd (调试配置) /MTd静态库并链接到该调试库。

Libraries that do not use the MSVC runtimes are not affected, and can be used with either debug or release builds without worries.不使用 MSVC 运行时的库不受影响,并且可以毫无顾虑地与调试或发布版本一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM