CMake交叉编译不会跳过编译器测试

发布于 2025-01-13 09:18:08 字数 1331 浏览 6 评论 0原文

我有以下问题:

我正在使用 CMake 为我的嵌入式项目进行构建配置。 为此,我使用 CMakeLists.txt 文件以及 flags.cmake 和 armgcc.cmake 工具链文件,在其中配置 arm-none-eabi-gcc 编译器的使用。

我使用以下命令调用 cmake:

cmake -DCMAKE_TOOLCHAIN_FILE="armgcc.cmake" -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=debug

但是当我尝试运行此命令时,我收到错误消息:

-- Check for working C compiler: .../10 2021.10/bin/arm-none-eabi-gcc.exe - broken
CMake Error at .../CMake/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    ".../10 2021.10/bin/arm-none-eabi-gcc.exe"

  is not able to compile a simple test program.

在官方 关于交叉编译的文档,它说我必须添加

set(CMAKE_SYSTEM_NAME Generic)

才能启用交叉编译。

我在 armgcc.cmake 文件以及 CMakeLists 文件的顶部添加了此命令,但出现了相同的错误。

仅当我添加

set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)

到我的 armgcc.cmake 文件时,测试才会被跳过,并且所有内容都会配置和构建良好。

有人可以告诉我我是否误解了什么或做错了什么吗? 为什么官方 CMAKE_SYSTEM_NAME 方法对我不起作用? 文档指出强制方法不应该用于 3.6 之后的版本。但没有它我就无法让它运行。

提前致谢 :) 此致 埃沃克斯

I have the following problem:

I'm using CMake to make a build configuration for my embedded project.
To do this, I'm utilizing a CMakeLists.txt file together with a flags.cmake and armgcc.cmake toolchain file where I configure the usage of the arm-none-eabi-gcc compiler.

I invoke cmake with the following command:

cmake -DCMAKE_TOOLCHAIN_FILE="armgcc.cmake" -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=debug

But when I try to run this I get the error message:

-- Check for working C compiler: .../10 2021.10/bin/arm-none-eabi-gcc.exe - broken
CMake Error at .../CMake/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    ".../10 2021.10/bin/arm-none-eabi-gcc.exe"

  is not able to compile a simple test program.

In the official documentation regarding cross compilation, it says that I have to add

set(CMAKE_SYSTEM_NAME Generic)

to enable cross compilation.

I added this command on top of the armgcc.cmake file as well as the CMakeLists file but get the same error.

Only when I add

set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)

to my armgcc.cmake file, the test is skipped and everything configures and builds fine.

Can someone tell me if I misunderstood something or am doing something wrong?
Why is the official CMAKE_SYSTEM_NAME approach not working for me?
The documentation states that the forced approach should not be used for versions newer than 3.6. but without it I am not able to get it running.

Thanks in advance :)
Best regards
Evox

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长安忆 2025-01-20 09:18:08

这样其他人可能会很快找到这个:

@u-235 向我推荐了 @KamilCuk 在这里发布的工作解决方案:stackoverflow.com/a/53635241/8699689

似乎 CMake 正在使用一组与操作系统相关的标志调用编译器测试以及与主机兼容的设置。然后,嵌入式编译器缺少正常工作和链接目标的引用和参数(更多信息请参见发布的解决方案)。

进行设置

set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") 

解决方案是在 CMake 文件中的 project() 命令之前

。官方文档也证实了这一点这里

我希望他们会在我用作参考的“Cross Compiling With CMake”一章中提到了这个选项。

谢谢你的回答:)
此致
埃沃克斯402

So that other people may find this fast:

@u-235 referred me to a working solution posted here by @KamilCuk: stackoverflow.com/a/53635241/8699689

It seems that CMake is invoking the compiler test with a set of OS related flags and settings to be compatible with the host. The embedded compiler is then missing references and arguments to work properly and link the target (more on that in the posted solution).

The solution is to set

set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") 

before the project() command in your CMake file.

The official documentation also confirms this here

I would have wished that they would mention this option in the "Cross Compiling With CMake" chapter that I used as reference.

Thanks for the answer :)
Best regards
Evox402

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文