如何使用cmake和Visual Studio 2017查找Boost库
我使用Visual Studio 2017编译了Boost 1.65.1如何使用cmake和Visual Studio 2017查找Boost库,boost,cmake,visual-studio-2017,Boost,Cmake,Visual Studio 2017,我使用Visual Studio 2017编译了Boost 1.65.1 使用CMADE编译某个C++项目时,未发现Boost库: cmake -G"Visual Studio 15 2017" -DBoost_COMPILER="-vc150" .. CMake Error at cmake-3.9/Modules/FindBoost.cmake:1900 (message): Unable to find the requested Boost libraries. Boost
使用CMADE编译某个C++项目时,未发现Boost库:
cmake -G"Visual Studio 15 2017" -DBoost_COMPILER="-vc150" ..
CMake Error at cmake-3.9/Modules/FindBoost.cmake:1900 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: C:/Boost/include/boost-1_65_1
Could not find the following Boost libraries:
boost_thread
boost_system
boost_regex
boost_timer
boost_filesystem
boost_serialization
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:18 (find_package)
图书馆有:
dir c:\Boost\lib
Volume in drive C has no label.
Directory of c:\Boost\lib
28/11/2017 12:47 <DIR> .
28/11/2017 12:47 <DIR> ..
...
28/11/2017 12:12 937.796 libboost_filesystem-vc150-mt-1_65_1.lib
28/11/2017 12:40 6.792.370 libboost_filesystem-vc150-mt-gd-1_65_1.lib
28/11/2017 12:20 996.592 libboost_filesystem-vc150-mt-s-1_65_1.lib
28/11/2017 12:17 5.951.092 libboost_filesystem-vc150-mt-sgd-1_65_1.lib
28/11/2017 12:28 996.456 libboost_filesystem-vc150-s-1_65_1.lib
28/11/2017 12:25 5.950.956 libboost_filesystem-vc150-sgd-1_65_1.lib
...
28/11/2017 12:13 13.418.950 libboost_regex-vc150-mt-1_65_1.lib
28/11/2017 12:40 43.663.182 libboost_regex-vc150-mt-gd-1_65_1.lib
28/11/2017 12:21 13.487.852 libboost_regex-vc150-mt-s-1_65_1.lib
28/11/2017 12:17 42.108.148 libboost_regex-vc150-mt-sgd-1_65_1.lib
28/11/2017 12:28 13.487.546 libboost_regex-vc150-s-1_65_1.lib
28/11/2017 12:25 42.107.842 libboost_regex-vc150-sgd-1_65_1.lib
28/11/2017 12:16 9.426.284 libboost_serialization-vc150-mt-1_65_1.lib
28/11/2017 12:43 33.389.696 libboost_serialization-vc150-mt-gd-1_65_1.lib
28/11/2017 12:24 10.690.636 libboost_serialization-vc150-mt-s-1_65_1.lib
28/11/2017 12:20 34.091.376 libboost_serialization-vc150-mt-sgd-1_65_1.lib
28/11/2017 12:31 10.690.106 libboost_serialization-vc150-s-1_65_1.lib
28/11/2017 12:27 34.090.846 libboost_serialization-vc150-sgd-1_65_1.lib
...
200 File(s) 2.184.720.662 bytes
2 Dir(s) 48.071.262.208 bytes free
没有提到“gd”或“sgd”标记,但我的LIB就是这样命名的。
我还尝试禁用所有可能使用这些标记的选项,但仍然失败:
cmake -G"Visual Studio 15 2017" -DBoost_COMPILER="-vc150" -DBOOST_LIBRARYDIR=/c/Boost/lib -DBoost_USE_STATIC_RUNTIME=OFF -DBoost_USE_DEBUG_RUNTIME=OFF ..
CMake Error at cmake-3.9/Modules/FindBoost.cmake:1900 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: C:/Boost/include/boost-1_65_1
Could not find the following Boost libraries:
boost_thread
boost_system
boost_regex
boost_timer
boost_filesystem
boost_serialization
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:18 (find_package)
关于库命名: Boost库(.lib、.dll on Win、.a、.so on Linux)的名称有3种形式。它们依赖于构建boost时传递给
b2
的--layout
选项。在Windows上,默认值是版本控制的
,它生成您拥有的文件名。
您的问题的可能解决方案:
cmake-G“Visual Studio 15 2017”-DBoost_COMPILER=“-vc150”-DBoost_LIBRARYDIR=/c/Boost/lib…
但是,我不确定路径
/c/Boost/lib
是否对Windows CMake有效,请尝试c:\Boost\lib
顺便说一句,我将只定义
BOOST\u ROOT=C:\BOOST
,而不是BOOST\u LIBRARYDIR
Boost\u USE\u STATIC\u libs
是ON
(或通过命令行传递)。
如果您碰巧也使用python和/或numpy库,那么您需要为编译器定义BOOST\u python\u STATIC\u LIB
和BOOST\u numpy\u STATIC\u LIB
,当您包含这些LIB中的头时(例如:add\u definitions(-DBOOST\u python\u STATIC\u LIB-DBOOST\u numpython\u STATIC\u LIB)
)-DBoost\u DEBUG=ON
CMake文件打印了大量关于如何处理boost的信息
通常不需要设置
Boost\u USE\u multi-threaded
等变量,因为这些变量是由CMake检测到的。从“lib”目录文件列表中,我可以看到库文件的debug和release、动态和静态链接的C运行时版本都存在。我希望其中一些有帮助。捆绑的cmake可以在boost中找到预构建的windows二进制文件:。主要区别在于,这些库是按体系结构和编译器版本组织的,因此路径类似于:C:\local\boost\u 1\u 65\u 1\lib32-msvc-14.1和C:\local\boost\u 1\u 65\u 1\lib64-msvc-14.1。也许它只是在那些文件夹中寻找lib?
cmake -G"Visual Studio 15 2017" -DBoost_COMPILER="-vc150" -DBOOST_LIBRARYDIR=/c/Boost/lib -DBoost_USE_STATIC_RUNTIME=OFF -DBoost_USE_DEBUG_RUNTIME=OFF ..
CMake Error at cmake-3.9/Modules/FindBoost.cmake:1900 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: C:/Boost/include/boost-1_65_1
Could not find the following Boost libraries:
boost_thread
boost_system
boost_regex
boost_timer
boost_filesystem
boost_serialization
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:18 (find_package)