av4625
April 30, 2020, 1:24pm
1
Hi,
I wanted to have a directory structure like:
sketch
|
+-- code.ino
|
+--src
|
+-- cool_library
| |
| +-- thing.hpp
| +-- thing.cpp
|
+-- helper
| |
| +-- helper.hpp
| +-- helper.cpp
This works ok.
I found on some forum posts that code must go in a src directory so that solved my first issue but I cant find an answer to the following.
In code.ino I can include things like #include "src/cool_library/thing.hpp"
My problem is when the code in the folder needs a header from another folder.
For example if I want to use helper from thing.hpp i have to include like: #include "../helper/helper.hpp"
I don't like this and would like to be able to do: #include <src/helper/helper.hpp>
It would be really nice if sketch (or src) was setup as an include directory. Is it possible to do this or is there another better way?
system
April 30, 2020, 2:12pm
2
Is it possible to do this
No. When the helper.cpp file is compiled, the preprocessor knows only the relative path (./src/helper) to the source files. Any other files it needs need to be defined relative to that path.
is there another better way?
You have a way that works. What could be better than that?
Of course, you do not have to use the IDE with it's restrictions. You are free to invoke the compiler and linker directly, with the resulting full control over the arguments (and the restrictions of having to manually supply all those arguments).
av4625
April 30, 2020, 6:34pm
3
Ahh I thought as much, thanks for the answer.
The reason I wanted to change was because I changed the directory of a library and that meant all the includes were wrong. If the “include_directories” was set to src it would have been fine (obviously if something included the moved file that include will need changed regardless)
pert
April 30, 2020, 6:59pm
4
There's a feature request for this here:
opened 06:01PM - 04 Jul 18 UTC
type: enhancement
topic: code
### Describe the request
🙂 It will be easier for sketch developers to share a… sketch as a package that includes library dependencies, avoiding the need for each user to install the library dependencies.
🙂 Library dependencies of the sketch can be controlled, allowing them to be pinned to the specific versions the sketch was intended to be used with, independent from the version of any globally installations of the library. As an example there are major changes to the API of the very popular "**ArduinoJson**" library in version 6 and sketches only work with one or the other major version series of that dependency.
### Describe the current behavior
The common approach to bundling libraries with a sketch is to dump the library code files into the sketch root folder.
### Arduino CLI version
a58d5adbe269ecc55778c007dc8ac39ffd42ce85
### Operating system
All
### Operating system version
All
### Additional context
1. As a workaround in the preferences the sketchbook location ([`directories.user`](https://arduino.github.io/arduino-cli/dev/configuration/#configuration-keys)) can be set to the sketch folder. But this has to be done manually and changed every time another program is handled. So there could be some option for this to be set in the `.ino` file.
2. In the build folder a file `build.options.json` is generated automatically.
There are some options where additional library folders could possibly be added?
E.g.:
- builtInLibrariesFolders
- otherLibrariesFolders
#### Additional Requests
- https://github.com/arduino/arduino-ide/issues/150#issuecomment-830714850
- https://github.com/arduino/arduino-cli/issues/1255#issuecomment-568900798
- https://github.com/arduino/arduino-cli/issues/1255#issuecomment-671084645
- https://github.com/arduino/arduino-cli/issues/1255#issuecomment-751318119
- https://github.com/arduino/arduino-cli/issues/1255#issuecomment-750951958
- https://forum.arduino.cc/t/how-do-i-include-a-library-in-a-sketch-directory/1079812
- https://forum.arduino.cc/t/arduino-ide-cant-find-local-custom-libraries-in-relative-path/669421
- https://forum.arduino.cc/t/suggestion-improve-library-manager/847666
- https://forum.arduino.cc/t/using-generated-headers/912691
### Issue checklist
- [X] I searched for previous requests in [the issue tracker](https://github.com/arduino/arduino-cli/issues?q=)
- [X] I verified the feature was still missing when using the latest [nightly build](https://arduino.github.io/arduino-cli/dev/installation/#nightly-builds)
- [X] My request contains all necessary details
and what looks like some work to add the feature, but perhaps limited to one particular case, here:
arduino:master
← facchinm:inoz_experiment
opened 10:16AM - 24 Mar 17 UTC