使用boost作为cmake的静态库

时间:2014-09-23 11:18:56

标签: c++ opencv boost

我正试图静态链接到boost和OpenCV。我设法链接到静态版本的OpenCV,但我有问题链接到静态版本的Boost。

在我的cmake中我有:

if (MSVC)
    add_definitions (-D_SCL_SECURE_NO_WARNINGS -D_USE_MATH_DEFINES )
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
else (MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif (MSVC)
set(Boost_USE_STATIC_LIBS   ON)
set(BOOST_ROOT $ENV{BOOST_DIR})
set(BOOST_LIBRARYDIR $ENV{BOOST_DIR}/lib64-msvc-11.0)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
find_package(Boost COMPONENTS filesystem REQUIRED)
add_executable(test test.cpp)
target_link_libraries(test
${Boost_FILESYSTEM_LIBRARY})

但是当我编译它时,我收到了这个错误:

 Error  4   error LNK2038: mismatch detected for 'test': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in test.obj libboost_filesystem-vc110-mt-gd-1_55.lib(path_traits.obj)

如何解决这个问题?

0 个答案:

没有答案