Skip to content

Arduino sketches do not allow subdirectories for inclusion [imported] #1004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cmaglie opened this issue Nov 15, 2012 · 8 comments
Closed

Arduino sketches do not allow subdirectories for inclusion [imported] #1004

cmaglie opened this issue Nov 15, 2012 · 8 comments
Labels
Component: Compilation Related to compilation of Arduino sketches Component: IDE The Arduino IDE
Milestone

Comments

@cmaglie
Copy link
Member

cmaglie commented Nov 15, 2012

This is Issue 1004 moved from a Google Code project.
Added by 2012-08-10T11:05:20.000Z by mackatack.
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium

Original description

I have a rather big (open source) project with quite a lot of files that I would like to move to subdirectories within the sketch directory.

for example:

sketch.ino
sketch.h
subdir/sub2/file.h
subdir/sub2/file.cpp
lib/libraryname/lib.h
utils/utilname/util.h

At this moment I cannot include files in subdirectories by using #include "subdir/sub2/file.h" because the files do not get copied to the temporary compilation directory. As a consequence I get the following order while compiling: "error: subdir/file.h: No such file or directory".

It's quite common that source code is split up in different logical folders as the developer sees fit. Please support subdirectories by copying all the files and directories to the compilation directory. The files in the subdirs should then also be able to include files in parent directories; #include "../parent.h" for example.

@ffissore
Copy link
Contributor

ffissore commented Jul 1, 2015

Fixed since 8e2c3c7 and available in latest hourly build http://www.arduino.cc/en/Main/Software#hourly

@ffissore ffissore closed this as completed Jul 1, 2015
@ffissore ffissore added Component: IDE The Arduino IDE Component: Compilation Related to compilation of Arduino sketches labels Jul 1, 2015
@ffissore ffissore added this to the Release 1.6.6 milestone Jul 1, 2015
@ffissore ffissore self-assigned this Jul 1, 2015
@SuperTango
Copy link

This isn't working for me. (Or i'm doing it wrong...)

Example code can be found at https://github.com/SuperTango/SubDirTest

In this example, I have a simple sketch that uses a library called "KellyKLS_Serial".

When the KellyKLS_Serial.cpp and KellyKLS_Serial.h files are in the sketch directory, everything works fine. (This can be seen by checking out the above repo and using the "lib_in_sketch_dir" tag).

If I move the .cpp and .h files into a directory called "KellyKLS_Serial", the files are copied into the temporary directory properly, but the build fails with the errors:

Arduino: 1.6.6 (Mac OS X), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

WARNING: Spurious .git folder in 'USB Host Shield Library 2.0' library
sketch/SubDirTest.ino.cpp.o: In function `setup':
/Users/tango/src/Arduino/SubDirTest/SubDirTest.ino:6: undefined reference to `KellyKLS_Serial::init(Stream*)'
sketch/SubDirTest.ino.cpp.o: In function `__static_initialization_and_destruction_0':
/Users/tango/src/Arduino/SubDirTest/SubDirTest.ino:3: undefined reference to `KellyKLS_Serial::KellyKLS_Serial()'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling.

(Note, full errors at https://gist.github.com/SuperTango/c9a706fcfe16d7221a07)

this can be seen by checking out the "lib_in_subdir" tag from the repo referenced above.

Note that due to caching, If I built successfully as in the first example, I needed to rebuild the whole thing (i did it by quitting arduino-1.6.6) in order to see the second build fail.

@ffissore
Copy link
Contributor

ffissore commented Nov 5, 2015

@SuperTango you're right. files are copied but not compiled. I'm working on it

ffissore pushed a commit to arduino/arduino-builder that referenced this issue Nov 5, 2015
@ffissore ffissore reopened this Nov 5, 2015
@ffissore ffissore modified the milestones: Release 1.6.7, Release 1.6.6 Nov 5, 2015
@ffissore
Copy link
Contributor

ffissore commented Nov 5, 2015

@SuperTango fixed in the hourly builds http://www.arduino.cc/en/Main/Software#hourly. Thank you for the heads up

@ffissore ffissore closed this as completed Nov 5, 2015
@SuperTango
Copy link

Thanks very much!

@francescom
Copy link

Hello. Might this still be an issue in nov/2018 on IDE 1.8.7? I have a subfolder full of .cpp files and I get a whole lot of "undefined reference to" errors. Wasn't it fixed in 2015?

@agdl
Copy link
Member

agdl commented Nov 21, 2018

You must have a folder called src in your sketch folder then:

#include "src/myFolder/myFile.h"

@rynbrd
Copy link

rynbrd commented Nov 22, 2021

Is there a good reason this is limited to being in ./src/? This seems unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Compilation Related to compilation of Arduino sketches Component: IDE The Arduino IDE
Projects
None yet
Development

No branches or pull requests

7 participants