【发布时间】:2018-11-18 18:27:49
【问题描述】:
我想在Windows 上使用Boost 库,但这样做很麻烦。我从here下载了Windows包,解压到C:\Boost:
我在CMake 文件中添加了以下内容:
find_package(Boost 1.68 REQUIRED COMPONENTS filesystem)
# ...
target_link_libraries(MyExecutable ${Boost_LIBRARIES})
我收到以下CMake 错误:
C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" "-DCMAKE_C_COMPILER=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-gcc.exe" "-DCMAKE_CXX_COMPILER=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-g++.exe" -G "CodeBlocks - MinGW Makefiles" D:\Cpp\MyProject
CMake Error at C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):
Unable to find the requested Boost libraries.
Boost version: 1.68.0
Boost include path: C:/Boost
Could not find the following Boost libraries:
boost_filesystem
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:6 (find_package)
-- Configuring incomplete, errors occurred!
See also "D:/Cpp/MyProject/cmake-build-debug/CMakeFiles/CMakeOutput.log".
[Failed to reload]
它显然找不到filesystem,但它在C:\Boost\boost\filesystem 中(here 是FindBoost 上的文档)。
如何设置我的CMake 文件以正确使用Boost?我也尝试设置Boost 环境变量,但它仍然不起作用:
SET (BOOST_ROOT "c:/Boost")
SET (BOOST_INCLUDEDIR "c:/Boost/boost")
SET (BOOST_LIBRARYDIR "c:/Boost/libs")
FIND_PACKAGE(Boost 1.68.0 REQUIRED COMPONENTS filesystem)
【问题讨论】:
-
看起来你使用了错误的 cmake,也许你想检查你的
PATH优先级并将 JetBrains 的东西推到底部。 -
你用mingw编译过boost库吗?您的下载链接是源代码而不是 mingw 二进制文件。另请记住,您不能使用 Visual Studio 二进制文件。如果您确实下载了为您的工具链编译的二进制文件,请确保您。
-
因为我使用的是
CLionbyJetbrains,所以它是正确的CMake版本。另外,Boost说大多数东西都不需要编译,所以我没有这样做。
标签: c++ windows boost cmake boost-filesystem