How do you cross compile Arduino code using Arduino-Makefile?

I have an Arduino attached to a Raspberry Pi. Compiling the Arduino C code on an x86 machine in about 2 seconds, but doing the same compilation on the Pi takes over a minute.

However, if I compile the code on my x86 machine and rsync the files to the Pi, when I run make upload to install them onto the Arduino, I get errors like:

make: *** No rule to make target '/home/myuser/git/myproject/lib/ros_lib/ros.h', needed by 'build-leonardo/main.ino.o'.  Stop.

Apparently, many of the files written to the build- directory by the make process include absolute pathnames relative to the filesystem they were compiled on, and these pathnames are then used during make upload.

I tried to a recursive search-and-replace on the Pi, to replace my x86 user's path with the equivalent path on the Pi with:

find /usr/local/myproject/build-leonardo -type f -print0 | xargs -0 sed -i 's/\/home\/myuser\/git/\/usr\/local/g'

And this fixed the initial error, but now I get the error:

lto1: internal compiler error: cannot read LTO decls from build-leonardo/main.ino.o
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: /usr/share/arduino/hardware/tools/avr/bin/avr-gcc returned 1 exit status
/usr/share/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
/usr/share/arduino/Arduino.mk:1446: recipe for target 'build-leonardo/head2.elf' failed
make: *** [build-leonardo/head2.elf] Error 1

Does this mean the object files built on the x86 are in a format that can't be used on an ARM platform...even though they're intended for an Arduino, which is neither? Is there any way to compile an Arduino sketch so it's portable and can be uploaded to the Arduino from any other machine?

  • Moving partial compilations sounds like an exercise in frustration. If you build all the way through to a hex file, that can be flashed with anything that can run avrdude (or other solutions). Is there a reason you actually want to do any compilation on the pi, or do you merely want to use it to drive flashing? – Chris Stratton Jun 26 '17 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.