我用Visual 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’标签,但我的名字是那样的。我还试图禁用所有可以使用这些标记的选项,但仍然失败:
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)发布于 2018-09-13 09:25:51
关于库命名的:
Boost库(.lib,.dll on Win,.a,.so on Linux)名称有3种形式。它们依赖于--layout选项,该选项在构建boost时传递给b2。在Windows上,默认的是versioned,它生成您所拥有的文件名。请看我的详细解释。
您的问题的可能解决方案:
cmake -G"Visual Studio 15 2017" -DBoost_COMPILER="-vc150" -DBOOST_LIBRARYDIR=/c/Boost/lib ...
但是,我不确定路径/c/Boost/lib对于CMake是否有效,请尝试C:\Boost\lib。
顺便说一句,我将定义简单的BOOST_LIBRARYDIR,而不是BOOST_ROOT=C:\Boost。Boost_USE_STATIC_LIBS是CMake文件中的ON (或传递到命令行)。如果您碰巧也使用python和/或numpy库,那么当您包含来自这些库的头(例如:BOOST_PYTHON_STATIC_LIB )时,您也需要为编译器定义BOOST_NUMPY_STATIC_LIB和BOOST_NUMPY_STATIC_LIB。-DBoost_DEBUG=ON
CMake文件打印了很多关于它如何处理boost的信息。注意:
通常,您不需要设置Boost_USE_MULTITHREADED等变量,因为这些变量是由CMake检测的。从您的"lib“目录文件列表中,我可以看到调试和发布,动态地和静态地链接C运行时版本的库文件。
我希望这些都能帮上忙。
https://stackoverflow.com/questions/47533040
复制相似问题