Go Down

Topic: How to include from subfolder of sketch folder (Read 24604 times) previous topic - next topic

ZinggJM

Arduino IDE knows how to include .h and .cpp files from subfolders of library folders, e.g. <Fonts/*>.

But I have not been able to include such files from a subdirectory of the sketch folder.

Maybe I need to add to the include path, but don't know where.
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

PaulS

Including files from the libraries folder, and subfolders, uses <> around the path/file name.

Including files from the sketch folder, and subfolders, uses "" around the path/file name.
The art of getting good answers lies in asking good questions.

spycatcher2k

Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

ZinggJM

For some reason unknown to me, this does not work in my environment with Arduino 1.6.10

Code: [Select]
/***************************************************
  This is our GFX example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/

// this works, but needs copying to .../Arduino/libraries
//#include <GTFT_IO.h>
//#include <Adafruit_GTFT_ILI9341.h>

// this does not compile with my Arduino 1.6.10
//#include "GTFT_IO/GTFT_IO.h"
//#include "Adafruit_GTFT_ILI9341/Adafruit_GTFT_ILI9341.h"

// this does also not compile with my Arduino 1.6.10
#include "GTFT_IO\GTFT_IO.h"
#include "Adafruit_GTFT_ILI9341\Adafruit_GTFT_ILI9341.h"

GTFT_IO_SPI9 GTFT_IO(D4);

// For the Adafruit shield, these are the default.
#define TFT_DC D4
#define TFT_CS D8

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_GTFT_ILI9341 tft(TFT_CS, TFT_DC, -1, &GTFT_IO);

No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

PaulS

Since you clearly didn't write the libraries that you are using, why are they not in the libraries folder?
The art of getting good answers lies in asking good questions.

jimLee

Just toss the Adafruit stuff in your library folder. Works fine in there.

..least it does for me. I have the same stuff in mine.

-jim lee
PNW Ardiuno & Maker club
1012 9Th Street, Anacortes, WA 98221 (Around the back of building)

bperrybap

Example:

#include "mysubdir\mylibrary,h"
That is a backwards slash.
While it may work on Windows, it is incorrect.

--- bill

pert

In recent versions of the Arduino IDE(including 1.6.10) if you want to include libraries from the sketch folder you need to put them in a src subfolder. For example:

Blink
|_Blink.ino
|_src
   |_BlinkLib
       |_BlinkLib.h

Code: [Select]
#include "src/BlinkLib/BlinkLib.h"

bperrybap

#8
Jan 01, 2017, 04:38 am Last Edit: Jan 01, 2017, 04:39 am by bperrybap
In recent versions of the Arduino IDE(including 1.6.10) if you want to include libraries from the sketch folder you need to put them in a src subfolder. For example:

Blink
|_Blink.ino
|_src
   |_BlinkLib
       |_BlinkLib.h

Code: [Select]
#include "src/BlinkLib/BlinkLib.h"

There was lots of discussion about this in a github issue related to this.
See this github issue for the gory details: https://github.com/arduino/Arduino/issues/5186
The IDE copies the user sketch directory and files over to a working directory where it does the build and recently the IDE was modified to not copy any subdirectories except src so any headers in directories other than under src would not work. However after much discussion the Arduino team decided to change their mind and fixed it so that other sub directories would work again for include files which is the way it used to work.
I've not tested it but think the latest IDE (1.8.0) is now working the way it used to work and sub directories for header files works again, so depending on which version of the IDE it may or may not work.

--- bill

ZinggJM

Now everything has become clear. Thank you all for the clarification!

Happy New Year

Jean-Marc Zingg
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

ZinggJM

Since you clearly didn't write the libraries that you are using, why are they not in the libraries folder?
Because I try to adapt and enhance libraries for my use and for different hardware, and the Arduino IDE does not allow me to edit sources in subdirectories of .../Arduino/libraries.

ZinggJM
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

jimLee

 I went through the same thing when I wanted to write my own libraries and the tweak them later. Just use any other IDE or source editor to tweak things in the libraries. As long as you don't forget to save all before telling the IDE to compile & load, it works great.

-jim lee
PNW Ardiuno & Maker club
1012 9Th Street, Anacortes, WA 98221 (Around the back of building)

ZinggJM

... And because my libraries folder got cluttered and slows down Arduino IDE startup.
I started to move libraries that I rarely use into .../librariesAside.

Include now works with Arduino 1.8. But I got linker errors. It seems .cpp files don't get added.
But this needs further investigation; for now I have 1.8 on an alternate Notebook.

ZinggJM
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

PaulS

Quote
It seems .cpp files don't get added.
They do if the header file is included in your sketch. Sounds to me like you are trying to hide the use of a library. THAT is not allowed.
The art of getting good answers lies in asking good questions.

ZinggJM

They do if the header file is included in your sketch. Sounds to me like you are trying to hide the use of a library. THAT is not allowed.
You are welcome to check that yourself, as I have attached the files in question.
I know that I should add the copyright notice of the original to two files derived from this original, this will be done, but in the hurry to seek for a solution to that issue, I forgot this before zipping for this topic.
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

Go Up