为了避免使用boost库的dll,改为静态编译。
https://stackoverflow.com/questions/19303430/cmake-cannot-find-boost-libraries
https://stackoverflow.com/questions/13280823/cmake-not-finding-boost
cmake编译命令改为:
cmake .. -G"Visual Studio 14 2015" -DDISABLE_DYNAMIC_LIB=ON -DBOOST_ROOT="D:/dev3rd/vcpkg/packages/boost_x86-windows-static" -DCMAKE_BUILD_TYPE=DEBUG
to build boost statically for x86 use:
vcpkg install boost:x86-windows-static
然后,boost.cmake按如下设定:
if (NOT Boost_FOUND)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED coroutine context thread system date_time chrono regex)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
endif()
遗留问题:在boost.cmake中添加如下修改:
set(BOOST_INCLUDEDIR D:/dev3rd/vcpkg/packages/boost_x86-windows-static/include)
if(CMAKE_BUILD_TYPE EQUAL "DEBUG")
set(BOOST_LIBRARYDIR D:/dev3rd/vcpkg/packages/boost_x86-windows-static/debug/lib)
else()
set(BOOST_LIBRARYDIR D:/dev3rd/vcpkg/packages/boost_x86-windows-static/lib)
endif()
message("------------ BOOST_LIBRARYDIR:${BOOST_LIBRARYDIR} -------------")
并不能改变真正的BOOST_LIBRARYDIR,生成的vs项目仍然是使用/lib而不是/debug/lib目录作为boost库目录。所以还是需要在调试的时候手动去lib目录移动一下Debug版本的lib。