使用 CMake 和 MinGW 在 Windows 上使用 Boost 1.68.0 编译 C++ [英] Compiling C++ with Boost 1.68.0 on Windows using CMake and MinGW

查看:58
本文介绍了使用 CMake 和 MinGW 在 Windows 上使用 Boost 1.68.0 编译 C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Windows 上使用 Boost 库,但这样做很麻烦.我从

我将以下内容添加到我的 CMake 文件中:

find_package(Boost 1.68 REQUIRED COMPONENTS 文件系统)# ...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-win32seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-g++.exe" -G "CodeBlocks - MinGW Makefiles" D:\Cpp\MyProjectCMake 错误在 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 (信息):无法找到请求的 Boost 库.升压版本:1.68.0Boost 包含路径:C:/Boost找不到以下 Boost 库:boost_filesystem找到了一些(但不是全部)所需的 Boost 库.你可以需要安装这些额外的 Boost 库.或者,设置BOOST_LIBRARYDIR 到包含 Boost 库的目录或 BOOST_ROOT到 Boost 的位置.调用堆栈(最近调用优先):CMakeLists.txt:6 (find_package)-- 配置不完整,出现错误!另见D:/Cpp/MyProject/cmake-build-debug/CMakeFiles/CMakeOutput.log".[重新加载失败]

它显然找不到 filesystem 但它在 C:\Boost\boost\filesystem (

如何设置我的 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 文件系统)

解决方案

另外,Boost 说大多数东西都不需要编译,所以我没有这样做.

它找不到 boost::filesystem.因为 boost::filesystem 是少数需要编译的库之一(所有你必须在 find package 命令中指定的必须编译).

您需要先构建提升:

./booststrap.sh

然后:

bjam

它会选择任何可用的编译器,因此您可能需要手动设置合适的工具集.

I want to use the Boost library on Windows but doing so has been troublesome. I downloaded the Windows package from here and extracted it to C:\Boost:

I added the following to my CMake file:

find_package(Boost 1.68 REQUIRED COMPONENTS filesystem)
# ...
target_link_libraries(MyExecutable ${Boost_LIBRARIES})

I'm getting the following CMake error:

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]

It apparently cannot find filesystem but it's there in C:\Boost\boost\filesystem (here is the documentation on FindBoost).

How do I setup my CMake file to use Boost properly? I tried setting the Boost environment variables as well but it still didn't work:

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)

解决方案

Also, Boost says that most things don't have to be compiled so I didn't do that.

It cannot find the library boost::filesystem. Because boost::filesystem is one of the few libraries that need to be compiled (all the ones that you have to specify in the find package command have to be compiled).

You need to build boost first:

./booststrap.sh

And then:

bjam

It picks up whatever compiler is available, so you may have to set the proper toolset manually.

这篇关于使用 CMake 和 MinGW 在 Windows 上使用 Boost 1.68.0 编译 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆