stevearc / vim-arduino

Vim plugin for compiling and uploading arduino sketches
MIT License
344 stars 24 forks source link

Compilation fails when using multiple source files #31

Closed darksworm closed 3 years ago

darksworm commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

darksworm commented 4 years ago

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

stevearc commented 4 years ago

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

darksworm commented 3 years ago

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.

stevearc commented 3 years ago

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 https://github.com/arduino/arduino-cli/issues/948

stevearc commented 3 years ago

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