Skip to content

Compilation fails when using multiple source files #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
darksworm opened this issue Aug 12, 2020 · 7 comments
Closed

Compilation fails when using multiple source files #31

darksworm opened this issue Aug 12, 2020 · 7 comments

Comments

@darksworm
Copy link

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 empty

Try 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.

@darksworm
Copy link
Author

darksworm commented Aug 12, 2020

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.ino

Results 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:uno

@darksworm
Copy link
Author

Some time later... I don't know what I did, but it suddenly started working...

@darksworm
Copy link
Author

darksworm commented Aug 16, 2020

It has been working flawlessly ever since. It was probably a peculiarity with my system.

@stevearc
Copy link
Owner

Glad to hear it's working! LMK if you ever manage to repro

@darksworm
Copy link
Author

darksworm commented Oct 15, 2020

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:
wul-src
compiling wul.ino from a directory named src - does not work.

wul-wul
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.

@darksworm darksworm reopened this Oct 15, 2020
darksworm added a commit to darksworm/wake-up-light that referenced this issue Oct 15, 2020
@stevearc
Copy link
Owner

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

@stevearc
Copy link
Owner

Looks like the arduino-cli enhancement was declined. Seems like this is just the way Arduino works for the foreseeable future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants