The C compiler is not able to compile a simple test program when compiling using ARM-GNU toolchain

Hi!

I am trying to use cmake to generate files for an arm based stm32 board running FreeRTOS. I am using Unix Makefiles and arm-none-eabi-gcc and arm-none-eabi-g++ as C/C++ compilers but I keep getting errors such as “The C compiler is not able to compile a simple test program”.

Can someone please provide some help
Thanks
Szabolcs

@Szakmary_Szabolcs, this error typically occurs during cross-compiling when CMake attempts to test the compiler. To resolve this issue, you need to instruct CMake to utilize the static library instead.

To do so, please add the following lines to your toolchain file:

bashCopy code

# Without this flag, CMake is unable to pass the test compilation check
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

This configuration will enable CMake to properly handle the test compilation check during cross-compiling.

Additionally, I recommend taking a look at the following example on GitHub, which demonstrates how this solution can be implemented:

Before I got this error
[cmake] The C compiler
[cmake] "C:/ST/STM32CubeCLT/GNU-tools-for-STM32/bin/arm-none-eabi-gcc.exe
[cmake] is not able to compile a simple test program.

After adding the static libraty target compile, set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
[cmake] – The C compiler identification is GNU 11.3.1
[cmake] – The CXX compiler identification is GNU 11.3.1
[cmake] – Detecting C compiler ABI info
[cmake] – Detecting C compiler ABI info - done
[cmake] – Check for working C compiler: C:/ST/STM32CubeCLT/GNU-tools-for-STM32/bin/arm-none-eabi-gcc.exe - skipped
[cmake] – Detecting C compile features
[cmake] – Detecting C compile features - done
[cmake] – Detecting CXX compiler ABI info
[cmake] – Detecting CXX compiler ABI info - done
[cmake] – Check for working CXX compiler: C:/ST/STM32CubeCLT/GNU-tools-for-STM32/bin/arm-none-eabi-g++.exe - skipped
[cmake] – Detecting CXX compile features
[cmake] – Detecting CXX compile features - done
[cmake] – Configuring done (1.6s)
[cmake] – Generating done (0.0s)

So this is a good answer