2

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
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
The Origin
  • 135
  • 1
  • 10
  • My question is why does CMake give me compilation errors if I try to build. I'm also relatively new to CMake in general, so I don't know what to do. – The Origin Dec 12 '21 at 15:08
  • why do use mingw for embedded sotware? – 0___________ Dec 12 '21 at 15:25
  • You forgot to show the error message which is show by CMake itself, in its **output**. Neither files contains that error message. Without that error message content of the files you provide has a little sense. – Tsyvarev Dec 12 '21 at 15:44
  • @Tsyvarev Sorry, I have included the output of CMake. And I don't use MinGW directly for embedded software, but only to have the command make available. As I stated I use the arm-none-eabi-gcc to compile. – The Origin Dec 12 '21 at 15:51
  • Does https://stackoverflow.com/questions/23120137/cmake-cross-compiling-generate-invalid-linker-options answer your question? – KamilCuk Dec 12 '21 at 16:14
  • It seems you are cross-compiling, but in CMake cross-compiling is not just a setting of the compilers (`CMAKE_CXX_COMPILER` and `CMAKE_C_COMPILER`). You need to tell CMake that you are cross-compiling, via `CMAKE_SYSTEM_NAME` variable. This variable is normally set in the [toolchain file](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling). – Tsyvarev Dec 12 '21 at 16:43
  • I just tried setting CMAKE_SYSTEM_NAME to Generic, Win32 and Linux, but I still get an error. I also tried to set CMAKE_TRY_COMPILE_TARGET_TYPE to "STATIC_LIBRARY" which worked, but the linking into a new project gave me basically the same error. What am I doing wrong? – The Origin Dec 12 '21 at 17:19
  • `CMAKE_SYSTEM_NAME to Generic, Win32 and Linux, but I still get an error` Did you remove cmake cache or build folder and reconfigured clear project? Did you set the system name before `project()` call? – KamilCuk Dec 13 '21 at 11:52

1 Answers1

0

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

Mizux
  • 8,222
  • 7
  • 32
  • 48
  • Thank you very much, I really only needed to use a Toolchain file for my case :,) I used this toolchain file as reference: https://github.com/vpetrigo/arm-cmake-toolchains/blob/master/arm-gcc-toolchain.cmake Cheers! – The Origin Dec 13 '21 at 15:35
  • glad you make it, welcome to the CMake ecosystem and thanks for the link ;) – Mizux Dec 14 '21 at 08:36