CMake doesn't find boost

一个人想着一个人 提交于 2019-12-24 02:23:26

问题


Windows 7. 64bit. CMake 2.8.10.

Steps:

  • download boost: http://sourceforge.net/projects/boost/files/boost/1.51.0/
  • put it to C:\work\lib\boost_1_51_0-MT
  • open "Start->All Programs->Microsoft Visual Studio 2010->Visual Studio Tools->Visual Studio Command Prompt (2010)"
  • command:  
cd C:\work\lib\boost_1_51_0-MT
bootstrap.bat
bjam --toolset=msvc-10.0 --variant=release --build-type=complete -j 4 --with-regex --with-test --with-filesystem --with-date_time --with-random --with-system --with-thread --with-program_options --with-chrono --with-math stage link=static threading=multi runtime-link=static
  • command:  
set BOOST_ROOT=C:\work\lib\boost_1_51_0-MT
cmake M:\project

  Unable to find the requested Boost libraries.

  Boost version: 1.51.0

  Boost include path: C:/work/lib/boost_1_51_0-MT

  The following Boost libraries could not be found:

          boost_system
          boost_thread
          boost_random
          boost_chrono

  No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the
  directory containing Boost libraries or BOOST_ROOT to the location of
  Boost.

M:\project\CMakeLists.txt contains: (i need to link boost statically)

...
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
set(USE_STATIC_BOOST ON)
add_definitions(-DBOOST_THREAD_USE_LIB)
add_definitions(-DBOOST_ALL_NO_LIB)

find_package(Boost 1.48.0 COMPONENTS system thread random chrono REQUIRED)
...

This CMakeLists.txt is old and works on other boost installations (done by me and not me in past, but the recepies is lost).

Solved

set(Boost_USE_STATIC_LIBS ON)

...now CMake finds boost libraries! Although my "set(USE_STATIC_BOOST ON)" must have the same effect, but it doesnt...


回答1:


Solved

set(Boost_USE_STATIC_LIBS ON)

...now CMake finds boost libraries! Although my CMakeLists.txt has set(USE_STATIC_BOOST ON) which must have the same effect, but it doesnt...

To use set(Boost_USE_STATIC_LIBS OFF) you need to add:

if( WIN32 )
  # Needed for boost to turn off autolinking for dynamic linking
  add_definitions( -DBOOST_ALL_NO_LIB )
endif()

See more at: Linking boost library with Boost_USE_STATIC_LIB OFF on Windows



来源:https://stackoverflow.com/questions/13223707/cmake-doesnt-find-boost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!