0
votes

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

1
CMake checks a compiler even in case of cross-compiling. You can find an example of configuration with such check even in the book you refers to. Non-working check usually means problems with a toolchain (a fact that a toolchain works for your specific project doesn't mean correctness of the toolchain in general). For debug non-working check see the messages after the line "is not able to compile a simple test program".Tsyvarev
BTW, the documentation describes why a macro CMAKE_C_COMPILER_FORCED should be avoided: "The macros provided by this module were once intended for use by cross-compiling toolchain files when CMake was not able to automatically detect the compiler identification. Since the introduction of this module, CMake's compiler identification capabilities have improved and can now be taught to recognize any compiler." That is, inability to correctly check a compiler is no longer a CMake problem, it is a problem of toolchain itself.Tsyvarev
Hey, and thank you for your answers. I'm fairly confident that the compiler I'm using is working correctly (official ARM GNU GCC). The problem is, that the embedded compilers are not accessing standard libraries and therefore its missing references, like mentioned in the answer from @u-235. The solution of adding "set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")" before project(), works fine for me. Thank you very much :)Evox402

1 Answers

0
votes

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