Skip to main content
edited tags
Link
php_nub_qq
  • 223
  • 3
  • 10
Source Link
php_nub_qq
  • 223
  • 3
  • 10

How to include a file from another (parent) directory

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?