find_package() doesn't detect boost on Windows Cmake

守給你的承諾、 提交于 2019-12-29 14:52:07

问题


I'm using a windows system. I want to use the Boost library using CMake. I've installed boost on C:\boost_1_55_0\ Here is my CMakeLists.txt file

set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
find_package(Boost 1.55.0 COMPONENTS thread)

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS}) 
    LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
    add_executable (linking_with_boost main.cc sqr.cc)
    target_link_libraries(linking_with_boost ${Boost_LIBRARIES})
else()
    message(STATUS "Fail  asdasd!")
endif()

I'm getting --Could NOT find Boost Output:

$ cmake ../
-- Could NOT find Boost
-- Fail  asdasd!
-- Configuring done
-- Generating done
-- Build files have been written to: D:/ubuntu_share/programming/C++/practice/cm
ake/linking_with_boost/build_win

回答1:


On Windows 7 x64 I have Boost 1.58 installed to C:\SDKs\boost_1_58_0. In order to allow cMake to find all of the appropriate files, I had to add the following three system variables:

    BOOST_INCLUDEDIR    C:\SDKs\boost_1_58_0\
    BOOST_LIBRARYDIR    C:\SDKs\boost_1_58_0\lib64-msvc-12.0
    BOOST_ROOT          C:\SDKs\boost_1_58_0\boost



回答2:


In addition to the BOOST_ROOT I also had to set the BOOST_LIBRARYDIR variable to succeed. In my case this was c:\Program Files\boost_1_56_0\lib64-msvc-12.0




回答3:


You need to set the environment variable BOOST_ROOT to c:\boost_1_55_0 before running cmake. Also look at cmake --help-module FindBoost for more help.




回答4:


I spent many hours on this issue and finally resolved it by using a few variables outlined in FindBoost manual here https://cmake.org/cmake/help/v3.0/module/FindBoost.html

Following variables helped me:

set (Boost_DETAILED_FAILURE_MSG ON)
set (Boost_THREADAPI win32)
set (BOOST_ROOT "/boost_1_40_0")
set (Boost_LIBRARY_DIR  /boost_1_40_0/lib")
set (Boost_COMPILER "-vc")
set (Boost_USE_STATIC_RUNTIME ON)  
set (Boost_DEBUG ON)  #<---------- Real life saver


来源:https://stackoverflow.com/questions/20969280/find-package-doesnt-detect-boost-on-windows-cmake

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