【问题标题】:Cmake error: Could NOT find Boost (missing: Boost_INCLUDE_DIR)Cmake 错误:找不到 Boost(缺少:Boost_INCLUDE_DIR)
【发布时间】:2020-02-15 05:35:24
【问题描述】:

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

系统:windows 7
Cmake 版本:3.16.0-rc1
升压版本:boost_1_71_0。而boost是通过.exe文件安装的。
Gcc 版本:4.8.1(rev5,由 MinGW-W64 项目构建)
视觉工作室:vs 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" 时,出现错误说“找不到 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".

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

【问题讨论】:

    标签: boost cmake


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      在我解决了这个问题之后,感谢这里的 ToughMind,我遇到了这些问题:_Boost_COMPONENT_DEPENDENCIES 和 _Boost_MISSING_DEPENDENCIES。帮助我的是更新到最新的 cmake 版本,我从这里得到了答案:CMake finds Boost but the imported targets not available for Boost version

      【讨论】:

        【解决方案4】:

        我在 Linux/Manjaro 上遇到了类似的问题。确保安装了 boost,更具体地说是 boost 开发头文件。我安装了 boost 运行时库,但没有安装头文件。我安装了那些sudo pacman -S boost,它为我解决了这个问题。

        【讨论】: