C++ 在visual studio中使用内置boost库时:libboost_regex-vc120-mt-sgd-1_59.lib(instances.obj):错误LNK2038:检测到不匹配 问题
我正在学习boost库,以便将来在windows上的x64控制台应用程序中使用。我尝试了这里提供的最简单的示例: 我希望构建的boost库满足以下条件:C++ 在visual studio中使用内置boost库时:libboost_regex-vc120-mt-sgd-1_59.lib(instances.obj):错误LNK2038:检测到不匹配 问题,c++,visual-studio,boost,C++,Visual Studio,Boost,我正在学习boost库,以便将来在windows上的x64控制台应用程序中使用。我尝试了这里提供的最简单的示例: 我希望构建的boost库满足以下条件: 对于x64平台。我的控制台应用程序是处理3D数据的,所以x64是必须的 可以在visual studio中以调试模式和发布模式使用 构建为静态库。我的控制台应用程序需要在另一台计算机上运行 可以在多线程中使用。我需要多线程使我的程序尽可能快 我阅读了该网页上的说明,搜索了许多其他页面,并尝试了许多构建命令,例如: bjam --build-t
bjam --build-type=complete toolset=msvc-10.0 threading=multi link=static address-model=64
b2 variant=release --build-type=complete architecture=x86 address-model=64 stage
b2 runtime-link=static variant=release address-model=64
最后,我在x64调试模式下成功地构建了小型VisualStudio项目。但是,当我尝试释放模式时,会出现如下错误:
1>libboost_regex-vc120-mt-sgd-1_59.lib(instances.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(instances.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(regex.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(regex.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(regex_traits_defaults.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(regex_traits_defaults.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(static_mutex.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(static_mutex.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(w32_regex_traits.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(w32_regex_traits.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(regex_raw_buffer.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in Temp.obj
1>libboost_regex-vc120-mt-sgd-1_59.lib(regex_raw_buffer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in Temp.obj
1>libcpmtd.lib(stdthrow.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in Temp.obj
1>libcpmtd.lib(stdthrow.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MT_StaticRelease' in Temp.obj
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
我的分析
我正在使用Visual Studio 2013。“libboost_regex-vc120-mt-sgd-1_59.lib(regex.obj)”中的“sgd”似乎表示它是一个调试库。我搜索了%BOOST\u ROOT%\stage\lib。与libboost_regex一样,我有:
"C:\Program Files\boost\boost_1_59_0\stage\lib\libboost_regex-vc120-s-1_59.lib"
"C:\Program Files\boost\boost_1_59_0\stage\lib\libboost_regex-vc120-sgd-1_59.lib"
"C:\Program Files\boost\boost_1_59_0\stage\lib\libboost_regex-vc120-mt-1_59.lib"
"C:\Program Files\boost\boost_1_59_0\stage\lib\libboost_regex-vc120-mt-s-1_59.lib"
"C:\Program Files\boost\boost_1_59_0\stage\lib\libboost_regex-vc120-mt-sgd-1_59.lib"
"C:\Program Files\boost\boost_1_59_0\stage\lib\libboost_regex-vc120-mt-gd-1_59.lib"
我没有为visual studio指定libboost_regex-vc120-mt-sgd-1_59.lib,它是由visual studio自动选择的。所以,我想我要么未能构建真正需要的库,要么需要以某种方式设置项目属性
我的问题
您不想将release build与LIBCMTD链接。您是否尝试过在
C/C++>>代码生成>>运行库中更改release的运行库配置?
?好的,我再次阅读了这篇文章,刚刚解决了第一个问题。这是个错误。我对调试模式和发布模式使用了相同的属性表。在第一次测试中,我将libboost_regex-vc120-sgd-1_59.lib设置为调试模式的附加依赖项设置。当我进入发布模式时,VisualStudio似乎首先检查了指定的libboost_regex-vc120-sgd-1_59.lib并尝试使用,但出现了错误。在我删除此设置后,VisualStudio试图自己找到合适的lib,可能找到了libboost_regex-vc120-s-1_59.lib。问题2的答案:libboost_regex-vc120-sgd-1_59.lib和libboost_regex-vc120-s-1_59.lib有相似的点,这使得VisualStudio无法自动拒绝libboost_regex-vc120-sgd-1_59.lib。为什么?LIBCMTD用于什么?libcmt是一个CRT库。libcmtd是libcmt的调试版本(注意末尾的'd'。它代表'debug')。我将再次重复“您不想将发布版本链接到libcmtd”。将它与libcmt链接,或者您需要完全删除它,因为boost可能已经有了它。