Visual Studio 2017 compatibality with boost 1.64.0

2019-07-08 09:46发布

问题:

I have a project which uses boost 1.64.0 since I need boost process. Its CMakeList processed and the code compiled using Qt/Clion but when I use the same code with Visual Studio 2017 I got following error (bellow is output of boost 1.63.0 but I tried 1.64.0 at first time).

1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:987 ] _boost_TEST_VERSIONS = 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:989 ] Boost_USE_MULTITHREADED = ON
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:991 ] Boost_USE_STATIC_LIBS = ON
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:993 ] Boost_USE_STATIC_RUNTIME = 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:995 ] Boost_ADDITIONAL_VERSIONS = 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:997 ] Boost_NO_SYSTEM_PATHS = 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1065 ] Declared as CMake or Environmental Variables:
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1067 ]   BOOST_ROOT = 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1069 ]   BOOST_INCLUDEDIR = 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1071 ]   BOOST_LIBRARYDIR = 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1073 ] _boost_TEST_VERSIONS = 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1166 ] location of version.hpp: D:/Program Files/boost_1_63_0/boost/version.hpp
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1190 ] version.hpp reveals boost 1.63.0
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1276 ] guessed _boost_COMPILER = -vc150
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1286 ] _boost_MULTITHREADED = -mt
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1330 ] _boost_RELEASE_ABI_TAG = -
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1332 ] _boost_DEBUG_ABI_TAG = -gd
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1388 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = D:/Program Files/boost_1_63_0/bin/x64;D:/Program Files/boost_1_63_0/lib;D:/Program Files/boost_1_63_0/stage/lib;D:/Program Files/boost_1_63_0/lib64-msvc-15.0;D:/Program Files/boost_1_63_0/lib;D:/Program Files/boost_1_63_0/../lib;D:/Program Files/boost_1_63_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG   = D:/Program Files/boost_1_63_0/bin/x64;D:/Program Files/boost_1_63_0/lib;D:/Program Files/boost_1_63_0/stage/lib;D:/Program Files/boost_1_63_0/lib64-msvc-15.0;D:/Program Files/boost_1_63_0/lib;D:/Program Files/boost_1_63_0/../lib;D:/Program Files/boost_1_63_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
1> CMake Warning at C:/.../cmake-3.7/Modules/FindBoost.cmake:746 (message):
1>   Imported targets not available for Boost version 106300
1> Call Stack (most recent call first):
1>   C:/.../cmake-3.7/Modules/FindBoost.cmake:850 (_Boost_COMPONENT_DEPENDENCIES)
1>   C:/.../cmake-3.7/Modules/FindBoost.cmake:1439 (_Boost_MISSING_DEPENDENCIES)
1>   projects/Visualizer/CMakeLists.txt:121 (find_package)
1> 
1> 
1> CMake Warning at C:/.../cmake-3.7/Modules/FindBoost.cmake:746 (message):
1>   Imported targets not available for Boost version 106300
1> Call Stack (most recent call first):
1>   C:/.../cmake-3.7/Modules/FindBoost.cmake:850 (_Boost_COMPONENT_DEPENDENCIES)
1>   C:/.../cmake-3.7/Modules/FindBoost.cmake:1439 (_Boost_MISSING_DEPENDENCIES)
1>   projects/Visualizer/CMakeLists.txt:121 (find_package)
1> 
1> 
1> CMake Warning at C:/.../cmake-3.7/Modules/FindBoost.cmake:746 (message):
1>   Imported targets not available for Boost version 106300
1> Call Stack (most recent call first):
1>   C:/.../cmake-3.7/Modules/FindBoost.cmake:850 (_Boost_COMPONENT_DEPENDENCIES)
1>   C:/.../cmake-3.7/Modules/FindBoost.cmake:1439 (_Boost_MISSING_DEPENDENCIES)
1>   projects/Visualizer/CMakeLists.txt:121 (find_package)
1> 
1> 
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1527 ] Searching for SYSTEM_LIBRARY_RELEASE: libboost_system-vc150-mt-1_63;libboost_system-vc150-mt;libboost_system-mt-1_63;libboost_system-mt;libboost_system;libboost_system-vc150-mt-s-1_63;libboost_system-vc150-mt-s;libboost_system-mt-s-1_63;libboost_system-mt-s
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1569 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-vc150-mt-gd-1_63;libboost_system-vc150-mt-gd;libboost_system-mt-gd-1_63;libboost_system-mt-gd;libboost_system-mt;libboost_system;libboost_system-vc150-mt-s-gd-1_63;libboost_system-vc150-mt-s-gd;libboost_system-mt-s-gd-1_63;libboost_system-mt-s-gd
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1527 ] Searching for FILESYSTEM_LIBRARY_RELEASE: libboost_filesystem-vc150-mt-1_63;libboost_filesystem-vc150-mt;libboost_filesystem-mt-1_63;libboost_filesystem-mt;libboost_filesystem;libboost_filesystem-vc150-mt-s-1_63;libboost_filesystem-vc150-mt-s;libboost_filesystem-mt-s-1_63;libboost_filesystem-mt-s
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1569 ] Searching for FILESYSTEM_LIBRARY_DEBUG: libboost_filesystem-vc150-mt-gd-1_63;libboost_filesystem-vc150-mt-gd;libboost_filesystem-mt-gd-1_63;libboost_filesystem-mt-gd;libboost_filesystem-mt;libboost_filesystem;libboost_filesystem-vc150-mt-s-gd-1_63;libboost_filesystem-vc150-mt-s-gd;libboost_filesystem-mt-s-gd-1_63;libboost_filesystem-mt-s-gd
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1527 ] Searching for THREAD_LIBRARY_RELEASE: libboost_thread-vc150-mt-1_63;libboost_thread-vc150-mt;libboost_thread-mt-1_63;libboost_thread-mt;libboost_thread;libboost_thread-vc150-mt-s-1_63;libboost_thread-vc150-mt-s;libboost_thread-mt-s-1_63;libboost_thread-mt-s
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1569 ] Searching for THREAD_LIBRARY_DEBUG: libboost_thread-vc150-mt-gd-1_63;libboost_thread-vc150-mt-gd;libboost_thread-mt-gd-1_63;libboost_thread-mt-gd;libboost_thread-mt;libboost_thread;libboost_thread-vc150-mt-s-gd-1_63;libboost_thread-vc150-mt-s-gd;libboost_thread-mt-s-gd-1_63;libboost_thread-mt-s-gd
1> -- [ C:/.../cmake-3.7/Modules/FindBoost.cmake:1639 ] Boost_FOUND = 1
1> CMake Error at C:/.../cmake-3.7/Modules/FindBoost.cmake:1795 (message):
1>   Unable to find the requested Boost libraries.
1> 
1>   Boost version: 1.63.0
1> 
1>   Boost include path: D:/Program Files/boost_1_63_0
1> 
1>   Could not find the following static Boost libraries:
1> 
1>           boost_system
1>           boost_filesystem
1>           boost_thread
1> 
1>   No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the
1>   directory containing Boost libraries or BOOST_ROOT to the location of
1>   Boost.

As suggested here I downgrade boost to 1.63.0 but it got same error again.

Is there any suggestion about the problem(I am sure that I set the BOOST_ROOT, BOOST_INCLUDEDIR and BOOST_LIBRARYDIR appropriately)?

Can I upgrade VS2017-cmake to use cmake 3.8 (install cmake 3.8 separately and browse VS2017 to use it)?

VS2017(cmake 3.7) is compatible with which version of boost?

回答1:

I used Visual studio to compile a Cmake-based project which uses boost 1.64.0. The problem was Visual studio's CMake(v3.7) which is unable to find the boost libs/dlls. As figure out Dan Masek CMake add a token -vc141 to boost libs/dlls when build it and FindBoost must know it(token is -vc140, -vc141 or etc) in order to find them.

In the CMake(v3.7) this token is -v150 for boost which it build with Visual Studio 2017. Changing that with -v141 made every thing true.

Summary: In order to find Visual Studio 2017 boost libs/dlls: Find file FindBoost.cmake and at line 431 change set(_boost_COMPILER "-vc150") to set(_boost_COMPILER "-vc141").