How do you add libraries to app being compiled with Particle Dev?


#1

Ok, so I need the library file for HttpClient to run an app that I am working on (it is for Spark Core). I know you can include libraries with the web IDE but I just have no idea how to do it with Particle Dev. I tried taking the files from the web IDE and adding them to the folder that my program was in and that did not work. Does anyone know how to do this? Help is greatly appreciated :smile:


#2

How have you taken them of Particle Build (aka Web IDE)?
Did you download them from the GitHub link provided when you select the library?

If you did that, then you’d need to take all the .h/.cpp files out of the firmware folder (no other files and not the example folder tho’) and copy them along side your project INO (flat directory structure).
While the library files get included like #include "LibName/LibName.h" in Particle Build you have to do it like #include "LibName.h" in Particle Dev.

Do that and it should work :wink:


#3

So when I got the library files, I just copied and pasted the codes that were used in the web IDE into notepad and then named them the same name they were given in the web IDE (“application.cpp”, “HttpClient.cpp”, “HttpClient.h”). I added these files to the folder that the main app was in. Should I download them from the GitHub link instead?


#4

You don’t have to, if you got all the required files copy-pasted correctly - it’s just the more convenient way especially when dealing with bigger libraries.

But the `#include’ thing you still have to take care of.

And what does Particle Dev say, when you build?


#5

ok, so yeah. I wanted to do it like #include “HttpClient/HttpClient.h” in particle dev but I changed it now that you said to. I changed to having two include files, like so:

#include "HttpClient.cpp"
#include "HttpClient.h"

When I do that, it gives me errors saying multiple definition of ‘HttpClient::HttpClient()’ whenever it is used. When I post just:

#include "HttpClient.h"

it says there are no compile errors but it does not create a binary file for some reason (which is what I need it to do)


#6

also when i do just:

#include "HttpClient"

it just says: HttpClient: No such file or directory


#7

That’s the only correct line to use.

I’ve had issues with Particle Dev on Windows being picky when you’ve got blanks or “funny” characters in your project path.
What’s your path?


#8

thanks man. I figured it out.


#9

Good to hear :+1:

Any chance to tell us what you did? It might help others facing a similar problem.


#10

Ok, So there was a folder file that had spaces in it. I took out the spaces in the folder name. Idk if that was it. I also took out all files in the folder except “HttpClient.cpp, HttpClient.h, and the ino file”. I think taking out all the other files is what did it.


#11

I had same problem, and I put everything in same folder as accepted answer said , but now it says bad token in .h file Is there a problem with compiler or did I do something wrong?


#12

This was years ago, things have changed since.

The solution nowadays runs via the Library Manager.