0

I am working on an Arduino project with a friend and we need 2 external libraries, OneWire and DallasTemperature. I can easily install them on my computer and it will work completely fine, but I actually want to install them in my git folder, so anyone can instantly use my code. My folder structure is as follows:

project_folder/
> libraries/
  > OneWire/
    > OneWire.h and OneWire.cpp and so
  > DallasTemperature/
    > DallasTemperature.h and DallasTemperature.cpp and so
> project.ino

In the header files I had to change some references, mostly file paths, so #include <OneWire.h> became #include "../OneWire/OneWire.h" and so and and I got no errors there. In my project.ino I loaded both libraries using #include "libraries/OneWire/OneWire.h" and #include "libraries/DallasTemperature/DallasTemperature.h", which all seem to work, but when I verify my code I get the following error:

C:\Users\<my username>\AppData\Local\Temp\ccZFsuFb.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_project.ino.cpp.o.1999':

<artificial>:(.text.startup+0x5e): undefined reference to `OneWire::begin(unsigned char)'

<artificial>:(.text.startup+0x6a): undefined reference to `DallasTemperature::DallasTemperature(OneWire*)'

C:\Users\<my username>\AppData\Local\Temp\ccZFsuFb.ltrans0.ltrans.o: In function `setup':

C:\Users\<my username>\Documents\<project folder>/project.ino:13: undefined reference to `DallasTemperature::begin()'

C:\Users\<my username>\AppData\Local\Temp\ccZFsuFb.ltrans0.ltrans.o: In function `loop':

C:\Users\<my username>\Documents\<project folder>/project.ino:17: undefined reference to `DallasTemperature::requestTemperatures()'

C:\Users\<my username>\Documents\<project folder>/project.ino:19: undefined reference to `DallasTemperature::getTempCByIndex(unsigned char)'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Uno.

Is there a possibility to install these libraries in my project folder or do I really have to install them seperately on each system?

Alex Janse
  • 43
  • 6
  • Better suited for https://arduino.stackexchange.com/ – Eugene Sh. Feb 12 '20 at 21:38
  • 1
    You can add object files to your git repo, but I think that's generally considered bad practice,, there are other tools for creating and managing dependencies for third party libraries. But, considering this is a Arduino project with a friend and not a commercial production code base, add away. – yano Feb 12 '20 at 21:59
  • 1
    Using `git` for object files is really not a good idea. You'll need to push those every time you compile and all versions of them will be there. Cloning that repo after 10000 compilations will be a real pain. Use some cloud service for the object files and use git for the source code. – Ted Lyngmo Feb 12 '20 at 22:05
  • 1
    .cpp files are normally compiled and linked automatically when you include the header with the same name in the same folder. Noe clear what is wrong in this case. What does "and so" mean in your folder hierarchy? Is `OneWire::begin(unsigned char)` defined in OneWire.cpp (for example), or are there additional files that have not been compiled/linked? Switch on "Show verbose output" and add the full log to your question so we can see what the build system is actually doing. – Clifford Feb 12 '20 at 23:12
  • Looking at https://github.com/pbrook/arduino-onewire, there is no `OneWire::begin()`. There is a `DallasTemperature:begin()` and the other symbols however, so that does not explain the problem. – Clifford Feb 12 '20 at 23:32
  • 1
    All the examples I can find such as https://stackoverflow.com/questions/4705790/keeping-all-libraries-in-the-arduino-sketch-directory?rq=1 use a subfolder `"src"` rather than `"libraries"`, but I don't think that is necessary - just a convention, or possibly Cargo Cult programming. – Clifford Feb 12 '20 at 23:35

1 Answers1

1

Is there a possibility to install these libraries in my project folder or do I really have to install them seperately on each system?

The answer is of course yes, First you need an IDE can make relative including

you can update your Arduino IDE for version >= 1.6.10 and restructure your folder to be as following

|project_folder/
|>src/
|   |> OneWire/
|   |   > OneWire.h and OneWire.cpp and so
|   |> DallasTemperature/
|   |   > DallasTemperature.h and DallasTemperature.cpp and so
|> project.ino

and then include them from your sketch, like this

#include "src/OneWire/OneWire.h"
#include "src/DallasTemperature/DallasTemperature.h"

Recommend option

Ibram Reda
  • 1,882
  • 2
  • 7
  • 18