Windows库链接报错

摘要

编译器build类型不一致导致的编译问题

问题回溯

今天拿到别人已经编译好的库,发现在链接的时候出现了报错

 [9/9 12.7/sec] Linking CXX shared module bin\plugins\AsensingPlugin\AsensingPlugin.dll
 FAILED: bin/plugins/AsensingPlugin/AsensingPlugin.dll 
 cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --intdir=Plugins\AsensingPlugin\Plugin\CMakeFiles\AsensingPlugin.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\AsensingPlugin.rsp  /out:bin\plugins\AsensingPlugin\AsensingPlugin.dll /implib:lib\plugins\AsensingPlugin\AsensingPlugin.lib /pdb:bin\plugins\AsensingPlugin\AsensingPlugin.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO  /INCREMENTAL:NO /LTCG  && cd ."
 LINK: command "C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\AsensingPlugin.rsp /out:bin\plugins\AsensingPlugin\AsensingPlugin.dll /implib:lib\plugins\AsensingPlugin\AsensingPlugin.lib /pdb:bin\plugins\AsensingPlugin\AsensingPlugin.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO /INCREMENTAL:NO /LTCG /MANIFEST /MANIFESTFILE:bin\plugins\AsensingPlugin\AsensingPlugin.dll.manifest" failed (exit code 1120) with the following output:
 ag1.lib(filter.cpp.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”(AsensingPluginPlugin.cxx.obj 中)
 ag1.lib(filter.cpp.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“MD_DynamicRelease”(AsensingPluginPlugin.cxx.obj 中)
   正在创建库 lib\plugins\AsensingPlugin\AsensingPlugin.lib 和对象 lib\plugins\AsensingPlugin\AsensingPlugin.exp
 MSVCRT.lib(initializers.obj) : warning LNK4098: 默认库“msvcrtd.lib”与其他库的使用冲突;请使用 /NODEFAULTLIB:library
 ag1.lib(filter.cpp.obj) : error LNK2001: 无法解析的外部符号 __imp__invalid_parameter
 ag1.lib(filter.cpp.obj) : error LNK2001: 无法解析的外部符号 __imp__CrtDbgReport
 bin\plugins\AsensingPlugin\AsensingPlugin.dll : fatal error LNK1120: 2 个无法解析的外部命令
 ninja: build stopped: subcommand failed.
 15:07:29: 进程"C:\Program Files\CMake\bin\cmake.exe"退出,退出代码 1

划重点

 ag1.lib(filter.cpp.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”(AsensingPluginPlugin.cxx.obj 中)
 ag1.lib(filter.cpp.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“MD_DynamicRelease”(AsensingPluginPlugin.cxx.obj 中)

问题分析

库与库之间的变量不匹配:_ITERATOR_DEBUG_LEVEL和RuntimeLibrary,这个大概率是采用了不同的build版本编译所致,重新编译版本一致的库就得了

参考

_ITERATOR_DEBUG_LEVEL | Microsoft Learn

阅读剩余
THE END