我使用Visual Studio 2017编译了Boost 1.65.1。
使用cmake编译某些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
如何在此配置中使用Boost?
编辑:
我发现有一个命名问题。来自FindBoost.cmake:
# Boost_USE_MULTITHREADED - Set to OFF to use the non-multithreaded
# libraries ('mt' tag). Default is ON.
# Boost_USE_STATIC_LIBS - Set to ON to force the use of the static
# libraries. Default is OFF.
# Boost_USE_STATIC_RUNTIME - Set to ON or OFF to specify whether to use
# libraries linked statically to the C++ runtime
# ('s' tag). Default is platform dependent.
# Boost_USE_DEBUG_RUNTIME - Set to ON or OFF to specify whether to use
# libraries linked to the MS debug C++ runtime
# ('g' tag). Default is ON.
# Boost_USE_DEBUG_PYTHON - Set to ON to use libraries compiled with a
# debug Python build ('y' tag). Default is OFF.
# Boost_USE_STLPORT - Set to ON to use libraries compiled with
# STLPort ('p' tag). Default is OFF.
# Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS
# - Set to ON to use libraries compiled with
# STLPort deprecated "native iostreams"
# ('n' tag). Default is OFF.
# Boost_COMPILER - Set to the compiler-specific library suffix
# (e.g. "-gcc43"). Default is auto-computed
# for the C++ compiler in use. A list may be
# used if multiple compatible suffixes should
# be tested for, in decreasing order of
# preference.
# Boost_THREADAPI - Suffix for "thread" component library name,
# such as "pthread" or "win32". Names with
# and without this suffix will both be tried.
# Boost_NAMESPACE - Alternate namespace used to build boost with
# e.g. if set to "myboost", will search for
# myboost_thread instead of boost_thread.
没有提到'gd'或'sgd'标签,但我的libs就是这样命名的。 我还试图禁用所有可能使用这些标签的选项,但它仍然失败:
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)
答案 0 :(得分:2)
关于库的命名:
增强库名称(在Win上为.lib,.dll,在Linux上为.a,.so)名称具有3种形式。它们取决于构建boost时传递给--layout
的{{1}}选项。在Windows上,默认值为b2
,它会产生您拥有的文件名。
See my detailed explanation here.
可能的问题解决方案:
versioned
cmake -G"Visual Studio 15 2017" -DBoost_COMPILER="-vc150" -DBOOST_LIBRARYDIR=/c/Boost/lib ...
对Windows CMake是否有效,请尝试/c/Boost/lib
。C:\Boost\lib
而不是BOOST_LIBRARYDIR
。BOOST_ROOT=C:\Boost
是Boost_USE_STATIC_LIBS
(或在命令行中传递)。
如果您碰巧也使用python和/或numpy库,那么当您包含这些库的标头时,还需要为编译器定义ON
和BOOST_PYTHON_STATIC_LIB
(例如:{{ 1}})。BOOST_NUMPY_STATIC_LIB
注意:
通常,您不需要设置add_definitions(-DBOOST_PYTHON_STATIC_LIB -DBOOST_NUMPY_STATIC_LIB)
等变量,因为它们是由CMake检测到的。从您的“ lib”目录文件列表中,我可以看到存在调试和释放,动态和静态链接的库文件的C运行时版本。
See here about these letters in the library file names.
我希望其中一些帮助。