This is my structure
program/
src/
Makefile
main.ino
test.h
...
lib/
i2c.h
In main.ino
I include test.h
and in test.h
I'm trying to include i2c.h
but it is just not working, I keep getting:
make: *** No rule to make target 'i2c.h', needed by 'build-uno/main.ino.o'. Stop.
I tried including like this
// test.h
#include "../lib/i2c.h"
I also tried making a symlink to my lib folder in arduino libraries and adding it as a library in Makefile
sudo ln -s /home/pi/program/lib /usr/share/arduino/libraries/GAVR
# Makefile
ARDUINO_DIR = /usr/share/arduino
BOARD_TAG = uno
ARDUINO_PORT = /dev/ttyAMA0
ARDUINO_LIBS = GAVR
include /usr/share/arduino/Arduino.mk
I also tried making a symlink to lib inside the src directory
ln -s /home/pi/program/lib /home/pi/program/src/lib
None of the above had any effect, the error message stays the same.
How can I include a file from another directory in my program?
src
directory and I have posted the contents of it. I'm not aware how I must specify thelib
directory as part of the build process. I found many examples that suggest adding-I
togcc
but the arduino makefile does magic and I don't know how to add parameters to the compiler command.arduino-cli
because of how Arduino building is done - not in the source directory. You will have to work out what the build directory's path is relative to where your file is. If you are using a proper library, though, thenarduino-cli
will know that and handle it all for you.