在visual studio中使用构建的boost库时:libboost_regex-vc120-mt-sgd-1_59.lib(instances.obj):错误LNK2038:检测到不匹配

时间:2015-08-30 13:46:34

标签: c++ visual-studio boost

问题

我正在学习升级库,以便将来在Windows上的x64控制台应用程序中使用。我尝试了这里提供的最简单的例子:

http://www.boost.org/doc/libs/1_59_0/more/getting_started/windows.html#prepare-to-use-a-boost-library-binary

我希望构建的boost库满足以下条件:

  1. for x64 platform。我的控制台应用程序是处理3D数据,所以x64是必须的。
  2. 可以在调试模式和发布模式下在visual studio中使用。
  3. 构建为静态库。我的控制台应用程序需要在另一台计算机上运行。
  4. 可用于多线程。我需要多线程才能让我的程序尽可能快。
  5. 我阅读了该网页上的说明并搜索了许多其他页面并尝试了许多构建命令,例如:

    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 | Debug模式下成功构建了一个小型visual studio项目。但是,当我尝试发布模式时,我得到的错误如下:

    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.似乎" sgd" in" libboost_regex-vc120-mt-sgd-1_59.lib(regex.obj)"表示它是一个调试库。我搜索了%BOOST_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自动选择的。所以,我想我要么没有构建真正需要的lib,要么我需要以某种方式设置项目属性。

    我的问题

    1. 如何在发布模式下成功构建小项目?
    2. 构建boost时b2和bjam有什么区别?

1 个答案:

答案 0 :(得分:-1)

您不希望将发布版本与LIBCMTD链接起来。