a9183756-gh / Arduino-CMake-Toolchain

CMake toolchain for all Arduino compatible boards
MIT License
135 stars 40 forks source link

Unable to compile examples: "The C Compiler [...] is not able to compile a simple test program" #26

Closed RobertWilbrandt closed 4 years ago

RobertWilbrandt commented 4 years ago

I am currently unable to build your examples as described without modifying the Toolchain file.

Problem Description

I tried building your examples just as descrbed in the markdown file. After a first run, i set the board in BoardOptions.cmake to the arduino due (also tested with arduino uno). Re-running the cmake command leads to the following error:

> cmake -D CMAKE_TOOLCHAIN_FILE=../Arduino-toolchain.cmake ../Examples
-- Found Arduino Platform: /home/wilbrandt/.arduino15/packages/arduino/hardware/avr/1.8.2
-- Found Arduino Platform: /home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12
-- Selected Arduino Board: Arduino Due (Programming Port) [sam.arduino_due_x_dbg]
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc
-- Check for working C compiler: /home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/bin/make" "cmTC_5a574/fast"
    /usr/bin/make -f CMakeFiles/cmTC_5a574.dir/build.make CMakeFiles/cmTC_5a574.dir/build
    make[1]: Entering directory '/home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build/CMakeFiles/CMakeTmp'
    CMakeFiles/cmTC_5a574.dir/build.make:67: *** missing separator.  Stop.
    make[1]: Leaving directory '/home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_5a574/fast' failed
    make: *** [cmTC_5a574/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)

-- Configuring incomplete, errors occurred!

Workaround

After some googling this seems to be a common issue when crosscompiling with cmake. I was able to work around this problem by bypassing the compiler tests completely, but this doesn't seem like the correct way to do this. My workaround was simply adding the two lines

SET (CMAKE_C_COMPILER_WORKS 1)
SET (CMAKE_CXX_COMPILER_WORKS 1)

to Arduino-toolchain.cmake.

System

I am not quite sure which information is relevant to you, so i'll just post some system information here. I work on an ubuntu 18.04.4.

> cmake --version
cmake version 3.10.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

I use the current Arduino IDE with version 1.8.12.

Conclusion

As this seems to be a common problem with cross-compiling, it would be nice to find a usable fix for this. As i don't have any experience cross-compiling with cmake, any help would be appreciated.

a9183756-gh commented 4 years ago

This *** missing separator seems to be same/similar to the issue #25? Please attach the generated ArduinoSystem.cmake. Will try to see if there is any issue in that file.

I will not suggest to use CMAKE_C_COMPILER_WORKS, CMAKE_CXX_COMPILER_WORKS. I think it will just delay the error to the build time.

RobertWilbrandt commented 4 years ago

I attached the file over in the other issue, but it turns out this is actually the same issue and fixed by #27. For some reason i was convinced these were different problems. Thank you for the quick response.