Compilation fails when using multiple source files
darksworm opened this issue · 7 comments
User story: When writing more complicated arduino sketches, I want to split the code up into multiple files.
Issue: Currently if I try to use include to inclue another source file, the compilation fails.
How to recreate
Create two files in the same directory:
// test.c.ino
#include "test.h"
void setup() {}
void loop() {}// test.h
// this file is emptyTry to compile & upload the sketch and this error will appear:
test.c:1:10: fatal error: test.h: No such file or directory
19 #include "test.h"
20 ┆ ┆ ^~~~~~~~
21 compilation terminated.
22 exit status 1
This code, however, compiles and uploads successfully when using the arduino-ide.
Upon some further inspection this seems to be an issue with the arduino upload command.
arduino --upload --board arduino:avr:uno --port /dev/ttyUSB0 --pref programmer=arduino:avrispmkii --pref build.path=./build test.inoResults in the same error (this command is similar to that which is currently used in the plugin).
But this this works (after changing test.h to test.cpp):
arduino-cli compile -b arduino:avr:uno . -v --build-path `pwd`/build && arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:unoSome time later... I don't know what I did, but it suddenly started working...
It has been working flawlessly ever since. It was probably a peculiarity with my system.
Glad to hear it's working! LMK if you ever manage to repro
Just managed to reproduce it - the issue occurs when the main ino file is in a directory that is named differently than it.
In my case - my main source file is named wul.ino, so it expects that it's parent directory is called wul.
See attached gifs for reproduction steps & proof:

compiling wul.ino from a directory named src - does not work.

compiling wul.ino from a directory named wul - works.
I'm sure that this issue is isolated to the directory naming, but just in case, the source code I'm trying to compile is availlable here.
Unfortunately this seems to be a limitation of the Arduino toolchain. There has been some discussion and it's possible that this requirement will be lifted in the future arduino/arduino-cli#948
Looks like the arduino-cli enhancement was declined. Seems like this is just the way Arduino works for the foreseeable future.