You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CMake无法找到/usr/include下的Boost mp11组件问题求助

关于CMake查找Boost头文件库的问题

我被CMake搞疯了,想只使用部分Boost包,避免依赖整个Boost库。

成功的配置

以下CMake代码可以正常运行:

cmake_minimum_required(VERSION 3.20)
project(YOMM2 LANGUAGES CXX VERSION 1.5.2)

find_package(Boost REQUIRED)
message(STATUS "Boost is here: ${Boost_INCLUDE_DIRS}")

执行日志:

$ cmake -S . -B build
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.81.0/BoostConfig.cmake (found version "1.81.0")  
-- Boost is here: /usr/include
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/jll/dev/fpp/build

失败的配置

但指定mp11组件后无法运行:

cmake_minimum_required(VERSION 3.20)
project(YOMM2 LANGUAGES CXX VERSION 1.5.2)

find_package(Boost REQUIRED COMPONENTS mp11)
message(STATUS "Boost is here: ${Boost_INCLUDE_DIRS}")

执行报错:

$ cmake . -B build
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.81.0/BoostConfig.cmake:141 (find_package):
  Could not find a package configuration file provided by "boost_mp11"
  (requested version 1.81.0) with any of the following names:

    boost_mp11Config.cmake
    boost_mp11-config.cmake

  Add the installation prefix of "boost_mp11" to CMAKE_PREFIX_PATH or set
  "boost_mp11_DIR" to a directory containing one of the above files.  If
  "boost_mp11" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.81.0/BoostConfig.cmake:262 (boost_find_component)
  /usr/share/cmake-3.27/Modules/FindBoost.cmake:594 (find_package)
  CMakeLists.txt:5 (find_package)

Vcpkg下的成功案例

使用vcpkg及如下清单文件时可以正常运行:

{
  "name": "yomm2",
  "version": "1.5.3",
  "dependencies": [
    "boost-mp11"
  ]
}

执行日志:

$ cmake -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -S . -B build
-- Running vcpkg install
Detecting compiler hash for triplet x64-linux...
Compiler found: /usr/bin/c++
The following packages will be built and installed:
  * boost-cmake:x64-linux@1.85.0#1
...
-- Running vcpkg install - done
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /home/jll/dev/fpp/build/vcpkg_installed/x64-linux/share/boost/BoostConfig.cmake (found version "1.85.0") found components: mp11 
-- Boost is here: /home/jll/dev/fpp/build/vcpkg_installed/x64-linux/include
-- Configuring done (0.8s)
-- Generating done (0.0s)
-- Build files have been written to: /home/jll/dev/fpp/build

我使用的CMake版本为3.27.4。原本以为CMake会自动查找包配置文件或头文件(这似乎是CMake文档说明的),请问我的操作是否有误?

更新:发现警告信息

日志中出现如下警告:

/usr/share/cmake-3.27/Modules/FindBoost.cmake(2218):  set(Boost_${UPPERCOMPONENT}_HEADER ON )
/usr/share/cmake-3.27/Modules/FindBoost.cmake(2219):  message(WARNING No header defined for ${COMPONENT}; skipping header check  (note: header-only libraries have no designated component) )
CMake Warning at /usr/share/cmake-3.27/Modules/FindBoost.cmake:2219 (message):
  No header defined for mp11; skipping header check (note: header-only
  libraries have no designated component)
Call Stack (most recent call first):
  /home/jll/dev/vcpkg/installed/x64-linux/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package)
  /home/jll/dev/vcpkg/scripts/buildsystems/vcpkg.cmake:811 (include)
  CMakeLists.txt:5 (find_package)

内容的提问来源于stack exchange,提问作者yorel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 08:18:10