Using C Header files in a different directory

Hi,

I hope someone can help me.

I’m trying to set up some common libraries with my projects in directory on the root of my C drive.
We’re developing across Particle and Arduino and we run some common libraries that we need to manage with git, in addition to our projects.

Can someone help me understand how to get #include “” to work like this? I’ve spent several hours online and trying different pieces of advice on here and stack exchange and I’m not getting anywhere.

I want to leave the header files (and CPP Files) in

C:\Comp_Code\Comp-main-code-repository\Comp_Library

and have the projects as folders in

C:\Comp_Code\Comp-main-code-repository\AProjectFolder

I’ve tried

#include "C:/Comp_Code/Comp-main-code-repository/Comp_Library/TSRFM69_OLD/TSRFM69_OLD.h"
#include "C:/Comp_Code/Comp-main-code-repository/Comp_Library/TSProtocol_OLD/TSProtocol_OLD.h"

I’ve tried some of the compiler directives but I’m clearly not understanding how to use them properly as it keeps saying, “No such file or directory”

Thanks in advance.

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here using code tags.

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries \\fedfps\UserData\davidm\My Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10803 -build-path C:\Users\davidm\AppData\Local\Temp\arduino_build_161446 -warnings=none -build-cache C:\Users\davidm\AppData\Local\Temp\arduino_cache_150532 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Comp_Code\Comp-main-code-repository\TestFirmware0V5_A\TestFirmware0V5_A.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries \\fedfps\UserData\davidm\My Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10803 -build-path C:\Users\davidm\AppData\Local\Temp\arduino_build_161446 -warnings=none -build-cache C:\Users\davidm\AppData\Local\Temp\arduino_cache_150532 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Comp_Code\Comp-main-code-repository\TestFirmware0V5_A\TestFirmware0V5_A.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\davidm\AppData\Local\Temp\arduino_build_161446\sketch\TestFirmware0V5_A.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Adafruit_NeoPixel" "C:\Users\davidm\AppData\Local\Temp\arduino_build_161446\sketch\TestFirmware0V5_A.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Adafruit_NeoPixel" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\OneWire" "C:\Users\davidm\AppData\Local\Temp\arduino_build_161446\sketch\TestFirmware0V5_A.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Adafruit_NeoPixel" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\OneWire" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "C:\Users\davidm\AppData\Local\Temp\arduino_build_161446\sketch\TestFirmware0V5_A.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Adafruit_NeoPixel" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\OneWire" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master" "C:\Users\davidm\AppData\Local\Temp\arduino_build_161446\sketch\TestFirmware0V5_A.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Adafruit_NeoPixel" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\OneWire" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src" "C:\Users\davidm\AppData\Local\Temp\arduino_build_161446\sketch\TestFirmware0V5_A.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Adafruit_NeoPixel" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\OneWire" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-I\\fedfps\UserData\davidm\My Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src" "C:\Users\davidm\AppData\Local\Temp\arduino_build_161446\sketch\TestFirmware0V5_A.ino.cpp" -o "C:\Users\davidm\AppData\Local\Temp\arduino_build_161446\preproc\ctags_target_for_gcc_minus_e.cpp"
C:\Comp_Code\Comp-main-code-repository\TestFirmware0V5_A\TestFirmware0V5_A.ino:68:25: fatal error: TSRFM69_OLD.h: No such file or directory

 #include "TSRFM69_OLD.h"

                         ^

compilation terminated.

Using library Adafruit_NeoPixel at version 1.0.6 in folder: \\fedfps\UserData\davidm\My Documents\Arduino\libraries\Adafruit_NeoPixel 
Using library OneWire in folder: \\fedfps\UserData\davidm\My Documents\Arduino\libraries\OneWire (legacy)
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
Using library Arduino-Temperature-Control-Library-master at version 3.7.7 in folder: \\fedfps\UserData\davidm\My Documents\Arduino\libraries\Arduino-Temperature-Control-Library-master 
Using library EEPROM at version 2.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM 
exit status 1
Error compiling for board Arduino/Genuino Uno.

Zaprime: ``` C:\Comp_Code\Comp-main-code-repository\TestFirmware0V5_A\TestFirmware0V5_A.ino:68:25: fatal error: TSRFM69_OLD.h: No such file or directory

#include "TSRFM69_OLD.h"

This error doesn't match what you previously claimed to be doing:

Zaprime: ```

include "C:/Comp_Code/Comp-main-code-repository/Comp_Library/TSRFM69_OLD/TSRFM69_OLD.h"

Do that and then post the error output.

You're correct. I changed the directory structure when I was trying stuff earlier.

C:\Comp_Code\Comp-main-code-repository\TestFirmware0V5_A\TestFirmware0V5_A.ino:68:75: fatal error: C:/Comp_Code/Comp_Library/TSRFM69_OLD/TSRFM69_OLD.h: No such file or directory

 #include "C:/Comp_Code/Comp_Library/TSRFM69_OLD/TSRFM69_OLD.h"

                                                                           ^

compilation terminated.

Zaprime:
I’m trying to set up some common libraries with my projects in directory on the root of my C drive.

The Arduino IDE is not very kind to people (ordinary folks :wink: ) who want to do that.

The options seem to be
{a} put your common code in the place where the IDE normally looks for libraries and use #include
{b} provide a full path path name and use #include “full/path/to/file”
{c} include the library files in the same directory as your .ino file (probably not suitable for your case).

I have written a short Python program that calls the command line IDE to compile and upload code after copying all relevant files into a standard directory structure. It allows me to use civilized relative links to external files.

…R

Apparently Zaprime is already doing b without success. I don’t know why because it works for me in some quick tests.

The only problem that comes to mind with that approach is if the library author incorrectly used the #include <foo.h> syntax to include internal library files. That will normally work if the library is in a standard library folder, which is why it’s pretty common, but not in the {b} or {c} usages. Easy enough to fix by just changing the library to use the #include "foo.h" syntax. I was hoping the full error message would reveal that was the problem but nope.

I just put my common code in a folder called common and then simply copy all the common file I want to use to my project folder. Any changes I make to the common files I coppy back to the common folder.

A little cumbersome but not too inconvenient if you are only dealing with a dozen or so common files.

At least it is much more convenient than dicking around with libraries that you can't edit directly with the IDE.