ccmakearm-none-eabi-gcc

CMake C project does not compile under arm-none-eabi toolchain


I am currently working on a driver for a sensor. As I did the setup, everything worked correctly and I could compile my code. But as soon as I have written the driver and wanted to test, CMake gave me lots of errors which I can't quite understand. Here are the outputs (pastebin):

CMakeError.log: https://pastebin.com/2jSRqCCs

CMakeOutput.log: https://pastebin.com/2Sy4pdXb

CMakeCache.txt: https://pastebin.com/KpFCTexM

I use the operating system Windows 10 and compile the code with arm-none-eabi-gcc. For Makefile compilation I use mingw32-make.

Thank you in advance!

Edit

CMakeLists.txt

# CMake minimum version
cmake_minimum_required(VERSION 3.12)

project(mpu9250_driver
    VERSION 1.0 
    DESCRIPTION "MPU9250 general purpose driver"
    LANGUAGES C CXX
)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
enable_language(C CXX)

add_library(mpu9250_driver STATIC
    src/MPU9250.c
)

target_include_directories(mpu9250_driver PUBLIC
    ./include
)

CMake Output:

[main] Building folder: driver-mpu9250 
[main] The folder containing the CMake cache is missing. The cache will be regenerated.
[main] Configuring folder: driver-mpu9250 
[proc] Executing command: "G:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=MinSizeRel "-DCMAKE_C_COMPILER:FILEPATH=G:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\bin\arm-none-eabi-gcc.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=G:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\bin\arm-none-eabi-g++.exe" "-Hc:/Users/User/Documents/Visual Studio Code/pico/driver-mpu9250" "-Bc:/Users/User/Documents/Visual Studio Code/pico/driver-mpu9250/build" -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 10.3.1
[cmake] -- The CXX compiler identification is GNU 10.3.1
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - failed
[cmake] -- Check for working C compiler: G:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.07/bin/arm-none-eabi-gcc.exe
[cmake] -- Check for working C compiler: G:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.07/bin/arm-none-eabi-gcc.exe - broken
[cmake] CMake Error at G:/Program Files/CMake/share/cmake-3.21/Modules/CMakeTestCCompiler.cmake:69 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "G:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.07/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/Documents/Visual Studio Code/pico/driver-mpu9250/build/CMakeFiles/CMakeTmp
[cmake]     
[cmake]     Run Build Command(s):G:/VSARM/mingw/bin/mingw32-make.exe -f Makefile cmTC_db21f/fast && G:/VSARM/mingw/bin/mingw32-make.exe  -f CMakeFiles\cmTC_db21f.dir\build.make CMakeFiles/cmTC_db21f.dir/build
[cmake]     mingw32-make.exe[1]: Entering directory 'C:/Users/User/Documents/Visual Studio Code/pico/driver-mpu9250/build/CMakeFiles/CMakeTmp'
[cmake]     Building C object CMakeFiles/cmTC_db21f.dir/testCCompiler.c.obj
[cmake]     G:\PROGRA~2\GNUARM~1\102021~1.07\bin\AR19DD~1.EXE    -o CMakeFiles\cmTC_db21f.dir\testCCompiler.c.obj -c "C:\Users\User\Documents\Visual Studio Code\pico\driver-mpu9250\build\CMakeFiles\CMakeTmp\testCCompiler.c"
[cmake]     Linking C executable cmTC_db21f.exe
[cmake]     "G:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_db21f.dir\link.txt --verbose=1
[cmake]     "G:\Program Files\CMake\bin\cmake.exe" -E rm -f CMakeFiles\cmTC_db21f.dir/objects.a
[cmake]     G:\PROGRA~2\GNUARM~1\102021~1.07\bin\ARM-NO~2.EXE qc CMakeFiles\cmTC_db21f.dir/objects.a @CMakeFiles\cmTC_db21f.dir\objects1.rsp
[cmake]     G:\PROGRA~2\GNUARM~1\102021~1.07\bin\AR19DD~1.EXE -Wl,--whole-archive CMakeFiles\cmTC_db21f.dir/objects.a -Wl,--no-whole-archive -o cmTC_db21f.exe -Wl,--out-implib,libcmTC_db21f.dll.a -Wl,--major-image-version,0,--minor-image-version,0 
[cmake]     g:/progra~2/gnuarm~1/102021~1.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: unrecognized option '--major-image-version'
[cmake]     g:/progra~2/gnuarm~1/102021~1.07/bin/../lib/gcc/arm-none-eabi/10.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]     CMakeFiles\cmTC_db21f.dir\build.make:98: recipe for target 'cmTC_db21f.exe' failed
[cmake]     mingw32-make.exe[1]: *** [cmTC_db21f.exe] Error 1
[cmake]     mingw32-make.exe[1]: Leaving directory 'C:/Users/User/Documents/Visual Studio Code/pico/driver-mpu9250/build/CMakeFiles/CMakeTmp'
[cmake]     Makefile:126: recipe for target 'cmTC_db21f/fast' failed
[cmake]     mingw32-make.exe: *** [cmTC_db21f/fast] Error 2
[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:4 (project)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "C:/Users/User/Documents/Visual Studio Code/pico/driver-mpu9250/build/CMakeFiles/CMakeOutput.log".
[cmake] See also "C:/Users/User/Documents/Visual Studio Code/pico/driver-mpu9250/build/CMakeFiles/CMakeError.log"
https://pastebin.com/hz5ARaiY

Solution

  • You need to use a CMAKE_TOOLCHAIN_FILE instead of your hackish compiler change without any sysroot etc...

    -DCMAKE_C_COMPILER:FILEPATH=G:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\bin\arm-none-eabi-gcc.exe"
    

    ref: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html