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

Tou*_*ind 5 boost cmake

我是 Cmake 和 Boost 的新手。我现在正在使用 cmake 开发一个程序,需要帮助。

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

当我cmake ..builddir 中运行时,没有发生错误。输出是:

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
Run Code Online (Sandbox Code Playgroud)

但我想使用 minGW 进行编译,所以当我朗姆酒时cmake -G "MinGW Makefiles",出现错误,说“找不到 Boost(缺少: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".
Run Code Online (Sandbox Code Playgroud)

运行时报错如何解决cmake -G "MinGW Makefiles"?谢谢你们!

Tou*_*ind 5

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


小智 5

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

mkdir buildtest; cd buildtest
cmake -DBOOST_ROOT=/you_path_to_boost/boost ..
cmake --build . -- -j 4
Run Code Online (Sandbox Code Playgroud)