a9183756-gh / Arduino-CMake-Toolchain

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

The CXX compiler identification is unknown (Optiboot) #34

Closed hacki11 closed 3 years ago

hacki11 commented 4 years ago

Hi, having my Board as mega 2560 everything is fine. All compilers are found and perfectly used. But now i have burned Optiboot onto my mega and selected the optiboot2560 board.

Now it searches avr-gcc and avr-g++ in paths where no binary is located. avr-gcc and avrg++ are available via Path. I have added CMAKE_CXX_COMPILER and CMAKE_C_COMPILER but no success.

Can you give me any pointers where i could possibly look? I can't tell if the optiboot files are wrong or there is something with arduino toolchain.

hacki@lx-hacki:~/git/homeduino$ cmake -DCMAKE_TOOLCHAIN_FILE=~/git/Arduino-CMake-Toolchain/Arduino-toolchain.cmake -G "CodeBlocks - Unix Makefiles" .
/usr/share/arduino
-- Found Arduino package /home/hacki/.arduino15/package_index.json
-- Found Arduino package /home/hacki/.arduino15/package_optiboot_optiboot-additional_index.json
-- Found Arduino package /usr/share/arduino/hardware/package_index_bundled.json
-- Found Arduino Platform: /usr/share/arduino/hardware/arduino/avr
-- Found Arduino Platform: /home/hacki/.arduino15/packages/Optiboot/hardware/avr/0.8.0
-- Selected Arduino Board: Optiboot on Mega2560 [avr.optiboot2560]
-- The CXX compiler identification is unknown
-- Indexing Arduino libraries for the project
CMake Error at CMakeLists.txt:3 (project):
  The CMAKE_CXX_COMPILER:

    /home/hacki/git/homeduino/_pkg_mgr/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

-- Configuring incomplete, errors occurred!
See also "/home/hacki/git/homeduino/CMakeFiles/CMakeOutput.log".
See also "/home/hacki/git/homeduino/CMakeFiles/CMakeError.log".

Board from Optiboot set(ARDUINO_BOARD "avr.optiboot2560") # Optiboot on Mega2560

CMakeError.log

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /home/hacki/git/homeduino/cmake-build-debug/_pkg_mgr/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ 
Build flags: 
Id flags:  

The output was:
No such file or directory
a9183756-gh commented 4 years ago

I tried compiling for the Optiboot on Mega2560 here, and it seems to be working well.

From the above error message, it looks like the toolchain expects the compiler inside /usr/share/arduino/hardware/tools/avr (Location of Arduino installation), but could not find. So it tries to find alternative package manager path in /home/hacki/git/homeduino/_pkg_mgr/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 and could not find there as well (Since package manager is not enabled). Toolchain never looks for the compiler from PATH (It is not as per the specification). Where is it located in your installation, that may provide a clue?

You may try providing the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER paths in the the generated ArduinoSystem.cmake in the build directory. However this file can get overwritten whenever BoardOptions.cmake is changed and is not a reliable solution.

Alternatively, you may try using package manager, as given below, which downloads the compiler and uses, if not found in the expected locations.

cmake -D CMAKE_TOOLCHAIN_FILE=/path/to/Arduino-toolchain.cmake -D ARDUINO_BOARD_MANAGER_URL=https://github.com/Optiboot/optiboot/releases/download/v8.0/package_optiboot_optiboot-additional_index.json /path/to/Examples/01_hello_world
hacki11 commented 4 years ago
hacki@lx-hacki:~/git/homeduino$ locate avr-g++
/usr/bin/avr-g++
/usr/share/arduino/hardware/tools/avr/bin/avr-g++

acki@lx-hacki:~/git/homeduino$ locate avr-gcc
/usr/bin/avr-gcc
/usr/share/arduino/hardware/tools/avr/bin/avr-gcc

If i change avr-gcc and avr-g++ executables in ArduinoSystem.cmake and add the path /usr/share/arduino/hardware/tools/avr/bin to ARDUINO_FIND_ROOT_PATH it will work.

Using the BOARD_MANAGER_URL leads to the same issue. Seems there is a dependency to exactly this compiler:

acki@lx-hacki:~/git/homeduino$ cmake -DCMAKE_TOOLCHAIN_FILE=~/git/Arduino-CMake-Toolchain/Arduino-toolchain.cmake  -D ARDUINO_BOARD_MANAGER_URL=https://github.com/Optiboot/optiboot/releases/download/v8.0/package_optiboot_optiboot-additional_index.json --debug -D CMAKE_VERBOSE_MAKEFILE=VERBOSE .
ARDUINO_INSTALL_PATH:/usr/share/arduino
ARDUINO_PACKAGE_PATH:/home/hacki/.arduino15
ARDUINO_PREFERENCE_FILE:/home/hacki/.arduino15/preferences.txt
ARDUINO_SKETCHBOOK_PATH:/home/hacki/Arduino
-- Found Arduino package /home/hacki/git/homeduino/_pkg_mgr/package_optiboot_optiboot-additional_index.json
-- Found Arduino package /home/hacki/.arduino15/package_index.json
-- Found Arduino package /usr/share/arduino/hardware/package_index_bundled.json
-- Found Arduino Platform: /home/hacki/git/homeduino/_pkg_mgr/packages/Optiboot/hardware/avr/0.8.0
-- Selected Arduino Board: Optiboot on Mega2560 [avr.optiboot2560]
-- Platform dependency Optiboot 8.0 => 'Arduino AVR Boards' from 'Arduino'
-- Platform dependency Optiboot 8.0 => 'Arduino AVR Boards' from 'Arduino'
-- Tool dependency Optiboot 8.0 => 'avr-gcc (7.3.0-atmel3.6.1-arduino7)' from 'Arduino'
-- Tool dependency Optiboot 8.0 => 'avrdude (6.3.0-arduino17)' from 'Arduino'
-- Tool dependency Optiboot 8.0 => 'arduinoOTA (1.3.0)' from 'Arduino'
-- Tool dependency Optiboot 8.0 => 'avrdude (6.0.1-arduino5)' from 'Arduino'
-- Tool dependency Optiboot 8.0 => 'avr-gcc (7.3.0-atmel3.6.1-arduino7)' from 'Arduino'
-- Tool dependency Optiboot 8.0 => 'avrdude (6.3.0-arduino17)' from 'Arduino'
-- Tool dependency Optiboot 8.0 => 'arduinoOTA (1.3.0)' from 'Arduino'
_rule_cmd:/home/hacki/git/homeduino/_pkg_mgr/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc
hacki11 commented 4 years ago

now it will find the right compiler!

Edit: Wow, there is even an upload network task in my jetbrains clion ide. thanks for the effort you put in this project, it's awesome!

hacki11 commented 4 years ago

if i understood upload-network cmake target correctly, if have to create an additional make call with the required environment variables to the upload-network target, right?

like: grafik

a9183756-gh commented 4 years ago

Good to know that it worked after you refreshed your Arduino Installation. I still wonder why the alternative package manager did not work for you. In case you need this, you may try with a new build directory, and post the full error logs for analysis.

Network upload depends on the way you achieved network connectivity to the board. Some possible options that may work are

  1. esp-link in which case you may want to look at the Arduino specific comments there. upload-network arguments take these parameters. Be aware of the need of 5V/3.3V voltage conversion between Mega and ESP.
  2. ArduinoOTA if you are using some Ethernet/WiFi shield. If you copy the platform.local.txt as instructed, and then invoke the clean CMake build. upload-network parameters should change appropriately (taking only IP address, port and password).
hacki11 commented 4 years ago

I took option 2. Had to copy my platform.local.txt to /home/hacki/.arduino15/packages/Optiboot/hardware/avr/0.8.0. Then i can use the following make file run configuration with just NETWORK_IP, NETWORK_PASSWORD and TARGET like you said: grafik

Works:

Connecting to board ...  done
Uploading sketch ...  done
Flashing sketch ...  done

Sketch uploaded successfully
Built target upload-network

Thanks again, great work!

a9183756-gh commented 3 years ago

Will close this issue and label this as question as there are no changes made.