跳转到内容
新建笔记

[CMake] "D:/program/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe"[CMake] is not able to compile

这是一条 Windows 上配置 imx8_ad7606 工程失败的历史记录。完整日志和原建议保留如下;未提供工具链文件、工程源码或成功重试日志,本轮不把建议写成已完成修复。

下面是输出记录,不是可执行脚本。日志中的删除缓存动作也是历史输出,本轮没有操作原工程目录。

终端窗口
[main] 正在配置项目: imx8_ad7606
[driver] 删除 c:/Users/USER/Desktop/imx8_ad7606/build/CMakeCache.txt
[driver] 删除 c:%5CUsers%5CUSER%5CDesktop%5Cimx8_ad7606%5Cbuild%5CCMakeFiles
[proc] 正在执行命令: D:\program\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=D:\program\gcc-arm-none-eabi\bin\arm-none-eabi-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:\program\gcc-arm-none-eabi\bin\arm-none-eabi-g++.exe --no-warn-unused-cli -S C:/Users/USER/Desktop/imx8_ad7606 -B c:/Users/USER/Desktop/imx8_ad7606/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 13.3.1
[cmake] -- The CXX compiler identification is GNU 13.3.1
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - failed
[cmake] -- Check for working C compiler: D:/program/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe
[cmake] -- Check for working C compiler: D:/program/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe - broken
[cmake] CMake Error at D:/program/cmake/share/cmake-4.1/Modules/CMakeTestCCompiler.cmake:67 (message):
[cmake] The C compiler
[cmake]
[cmake] "D:/program/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe"
[cmake]
[cmake] is not able to compile a simple test program.
[cmake]
[cmake] It fails with the following output:
[cmake]
[cmake] Change Dir: 'C:/Users/USER/Desktop/imx8_ad7606/build/CMakeFiles/CMakeScratch/TryCompile-q51sv8'
[cmake]
[cmake] Run Build Command(s): D:/programXilinx/2025.1/Vivado/bin/ninja.exe -v cmTC_f190c
[cmake] [1/2] D:\program\gcc-arm-none-eabi\bin\arm-none-eabi-gcc.exe -std=gnu11 -o CMakeFiles/cmTC_f190c.dir/testCCompiler.c.obj -c C:/Users/USER/Desktop/imx8_ad7606/build/CMakeFiles/CMakeScratch/TryCompile-q51sv8/testCCompiler.c
[cmake] [2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && D:\program\gcc-arm-none-eabi\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_f190c.dir/testCCompiler.c.obj -o cmTC_f190c.exe -Wl,--out-implib,libcmTC_f190c.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
[cmake] FAILED: cmTC_f190c.exe
[cmake] C:\WINDOWS\system32\cmd.exe /C "cd . && D:\program\gcc-arm-none-eabi\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_f190c.dir/testCCompiler.c.obj -o cmTC_f190c.exe -Wl,--out-implib,libcmTC_f190c.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
[cmake] D:/program/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: unrecognized option '--major-image-version'
[cmake] D:/program/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: use the --help option for usage information
[cmake] collect2.exe: error: ld returned 1 exit status
[cmake] ninja: build stopped: subcommand failed.
[cmake]
[cmake]
[cmake]
[cmake]
[cmake]
[cmake] CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:28 (project)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[proc] 命令“D:\program\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=D:\program\gcc-arm-none-eabi\bin\arm-none-eabi-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:\program\gcc-arm-none-eabi\bin\arm-none-eabi-g++.exe --no-warn-unused-cli -S C:/Users/USER/Desktop/imx8_ad7606 -B c:/Users/USER/Desktop/imx8_ad7606/build -G Ninja”已退出,代码为 1

第一步 -c 编译已进入后续链接步骤;实际失败发生在测试程序的链接阶段,ARM 链接器不认识 --major-image-version。链接行还包含 .exe、--out-implib 和 kernel32 等 Windows 目标设置。因此不能仅凭“is not able to compile”断言编译器二进制损坏。

这说明探测时的目标平台设置与所选 ARM 裸机工具链不匹配;但日志不足以确定是缺少、未加载、过晚加载还是错误的工具链配置。仅设置 CMAKE_C_COMPILER/CMAKE_CXX_COMPILER 不会自动把完整目标系统描述补齐。日志使用 Vivado 目录里的 Ninja 是环境事实,不能据此认定它是根因。

原文建议在 VS Code 的 settings.json 中传入工具链文件:

settings.json
{
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE": "${workspaceFolder}/cmake/gcc-arm-none-eabi.cmake"
}
}

该片段含 // 注释,属于 JSONC,不能当作严格 JSON;它只是 CMake Tools 的参数入口,不包含工具链本身。应确认文件存在,并从扩展输出的实际配置命令核对参数是否传入;使用 presets 时还要核对当前所选配置及扩展模式。参见 CMake Tools 设置说明。

排查时先确定编译目标:i.MX8 工程名称并不能证明这里是在构建 Linux 用户态程序还是板上某个裸机核。裸机与 Linux 目标的编译器、目标系统、运行库和链接脚本不同,不能一律套用同一份 Generic 工具链。

  • 工具链应在首次 project()/语言启用前生效。CMake 的 --toolchain 或 -DCMAKE_TOOLCHAIN_FILE=... 会提前加载文件,见 CMake 4.1 工具链手册。
  • 核对目标系统、处理器、编译器路径及目标所需的 sysroot/启动文件/链接脚本;切换工具链时使用独立的新构建目录,不把删除已有工程作为默认修复。
  • 对确实不能在探测阶段链接可执行文件的工具链,可评估 CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY。它改变相应探测的目标类型,不验证最终固件链接、运行库或硬件运行,也不应掩盖错误的目标系统。
  • 重新检查完整探测日志,再分别验收真实目标的编译、链接与板上运行。去掉某个不支持的选项不等于完成整条工具链配置。

本轮只在 Linux/CMake 3.31.6 上使用宿主 GCC 做独立的平台参数和探测边界实验;未安装原 ARM GCC、复现 Windows/CMake 4.1 工程、运行 VS Code 或连接 i.MX8/AD7606 硬件。原故障保留未复现状态。


来源:CSDN 原文,首次发布于 2026-01-16。