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

Ubuntu22.04下Buildroot因主机CMake引发编译与依赖查找异常

问题分析:Ubuntu 22.04下Buildroot构建的CMake矛盾异常

问题现象

我的构建主机是Ubuntu 22.04,在Buildroot构建过程中遇到两种矛盾的异常:

1. 安装主机CMake后,编译器无法识别

执行sudo apt update && sudo apt install cmake或sudo apt install catkin(catkin包含cmake)后,运行make时出现编译器识别失败错误:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /home/gabriel/dev/repos/my_repo/output/my_board/host/bin/ccache
-- Check for working C compiler: /home/gabriel/dev/repos/my_repo/output/my_board/host/bin/ccache - broken
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/home/gabriel/dev/repos/my_repo/output/my_board/host/bin/ccache"

  is not able to compile a simple test program.

  It fails with the following output:
...

2. 卸载主机CMake后,TinyXML2依赖查找失败

执行sudo apt remove cmake卸载主机CMake后,编译器可正常识别,但make时出现TinyXML2查找失败错误:

CMake Error at CMakeLists.txt:8 (find_package):
  By not providing "FindTinyXML2.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "TinyXML2",
  but CMake did not find one.

  Could not find a package configuration file provided by "TinyXML2" with any
  of the following names:

    TinyXML2Config.cmake
    tinyxml2-config.cmake

  Add the installation prefix of "TinyXML2" to CMAKE_PREFIX_PATH or set
  "TinyXML2_DIR" to a directory containing one of the above files. If
  "TinyXML2" provides a separate development package or SDK, be sure it has
  been installed.

即便TinyXML2已本地安装,仍无法被CMake找到。

原因分析

1. 安装主机CMake后编译器识别失败

Buildroot默认会构建一套独立的交叉编译工具链和配套CMake,这套工具链是针对目标板优化的,与主机系统环境完全隔离。

当主机安装了系统级CMake(如apt提供的3.22版本),Buildroot可能会错误调用主机CMake而非自身构建的CMake。主机CMake的配置是针对本地x86编译环境的,无法正确识别Buildroot生成的交叉编译链(包括ccache包装的编译器),也无法关联Buildroot的交叉编译环境变量,导致无法编译测试程序,最终触发编译器检测失败。

2. 卸载主机CMake后TinyXML2查找失败

卸载主机CMake后,Buildroot会使用自身构建的CMake,但这套CMake的模块路径仅包含Buildroot自带的配置模块,无法访问主机系统中安装的TinyXML2配置文件。

此外,若TinyXML2是手动在主机安装而非通过Buildroot的package系统添加,Buildroot的交叉编译环境也无法使用主机的库文件——主机库是针对x86架构编译的,与Buildroot目标板的架构不兼容,即便找到配置文件也无法正常链接。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 13:34:37