Cmake错误:无法找到Boost(缺少:Boost_INCLUDE_DIR)

11

我对Cmake和Boost都很陌生。目前正在使用Cmake编写程序,并需要帮助。

系统:Windows 7
Cmake版本:3.16.0-rc1
Boost版本:boost_1_71_0,通过.exe文件安装。
Gcc版本:4.8.1(rev5),由MinGW-W64项目构建。
Visual Studio版本:2015

当我在“build”目录下运行cmake ..时,没有出现错误。输出如下:

The C compiler identification is MSVC 19.0.24215.1
The CXX compiler identification is MSVC 19.0.24215.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Found Boost: C:/local/boost_1_71_0 (found version "1.71.0")  
Boost_Found Success!
Found OpenCV: C:/Users/gph/opencv/binaries (found version "3.4.5") 
Found OpenCV: C:/Users/gph/opencv/binaries (found version "3.4.5") found components: core highgui imgproc videoio 
Configuring done

但是我想使用minGW进行编译,所以当我运行 cmake -G "MinGW Makefiles" 时,出现了错误提示"Could NOT find Boost (missing: Boost_INCLUDE_DIR)"。输出如下:

但我希望使用minGW来编译,因此当我执行cmake -G "MinGW Makefiles"命令时,出现了一个错误,显示"Could NOT find Boost (missing: Boost_INCLUDE_DIR)"。输出结果如下:

The C compiler identification is GNU 4.8.1
The CXX compiler identification is GNU 4.8.1
Check for working C compiler: C:/MinGW/bin/gcc.exe
Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/MinGW/bin/g++.exe
Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at C:/Users/gph/cmake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find Boost (missing: Boost_INCLUDE_DIR)
Call Stack (most recent call first):
  C:/Users/gph/cmake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  C:/Users/gph/cmake/share/cmake-3.16/Modules/FindBoost.cmake:2162 (find_package_handle_standard_args)
  CMakeLists.txt:34 (find_package)


Configuring incomplete, errors occurred!
See also "C:/Users/gph/Desktop/libvibe++/build/CMakeFiles/CMakeOutput.log".

如何解决运行 cmake -G "MinGW Makefiles" 时出现的错误?谢谢各位!

4个回答

9

我通过在find_package(Boost REQUIRED)之前添加句子set(BOOST_ROOT C:/local/boost_1_71_0)来解决这个问题。但是我仍然不知道为什么需要添加这个。


看起来像是一个 bug,请考虑报告 https://github.com/boostorg/boost - Sergei Krivonos
在通用情况下,在“b2 install”之后,它必须被自动检测到。 - Sergei Krivonos

5

您还可以在创建cmake项目(或在CLion和其他IDE中的CMake选项)期间设置变量BOOST_ROOT。例如:

mkdir buildtest; cd buildtest
cmake -DBOOST_ROOT=/you_path_to_boost/boost ..
cmake --build . -- -j 4

4

我在Linux/Manjaro上遇到了类似的问题,请确保已经安装了Boost,具体来说是安装了Boost开发头文件。我已经安装了Boost运行时库,但还没有安装头文件。我使用以下命令进行安装:sudo pacman -S boost,这解决了我的问题。


2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接