Go Down

Topic: #include and arduino library / build process (Read 4138 times) previous topic - next topic

zenocon

Hi, I was wondering why the Arduino IDE seems to mandate that library source code be placed in the IDE subdirectory named "libraries"?  Is there some way around this constraint?  I have tried including library source ".h/.cpp" in the same directory as my sketch .pde file.  I've also tried using the IDE's Sketch -> Add File.. menu to add the library source.  Nothing seems to work.  #include statements won't compile at all it seems unless you add them to the IDE's libraries directory.

This is kind of a bummer.  If I'm working, for example, on some source in github with other devs, it requires us all to manually copy/paste the library sources into each of our IDE's folders.  This can become a bit of a maintenance headache.  Consider if you want to update or modify a library.

It would be much nicer if I could develop in the same manner as a standard C/C++ project where you can #include source relative to the directory you're building out of.  For example, if I had a sketch dir like this:

mysketch/
  -- mysketch.pde
  -- SomeLibrary/
     -- SomeLibrary.h
     -- SomeLibrary.cpp

and in my sketch code:

#include "SomeLibrary/SomeLibrary.h"

or something similar...

In this manner, I can store all the code for the app as one self-contained distribution that can be checked out, versioned, and maintained easily.

Is there any way to do this with the current build tools?  I haven't had any luck with 022 version of Arduino IDE.  I haven't yet looked at the Makefile, but I'm guessing there must be a way to hack that so my build isn't required to have library source be in the IDE project folder?

Thanks in advance,
Davis

Yup...  That's just not how it works.  My view is once you start to have advanced needs like this, you've outgrown the Arduinio IDE which was not build for this kind of use.  Time to move to a makefile.

What I do for this is simply have a pile of repositories, one for each library, and one for the PDE & related files.  So I'd have

sketchdir/
  mysketch/
    mysketch.pde
    something.h
    something.cpp
    README.md
  libraries/
    sharedlib/
      sharedlib.h
      sharedlib.cpp

and then README.md would say, "Depends on the sharedlib library.  Get it here -url-"

This is for cases where I want to share code with people who ARE using the IDE.

This does seem somewhat reasonable, though.  if it's a LIBRARY, it's for more programs than just this one.  If it's for JUST this program, why not keep it in 'mysketch' dir?

mysketch/
  mysketch.pde
  something.h
  something.cpp

zenocon

Thanks for the response.  I am going to try the CMake system referenced in this forum and see if that suits my needs.

Quote
This does seem somewhat reasonable, though.  if it's a LIBRARY, it's for more programs than just this one.  If it's for JUST this program, why not keep it in 'mysketch' dir?


I haven't yet been able to compile in this way using the IDE.  I'm assuming that a Makefile has no constraints like this, but if I just drop some library source in the 'mysketch' dir along with a .pde file, it won't compile in the Arduino IDE.

I was able to make this work a different way.  If I click the button to create a new tab and make a new header file (e.g. myheader.h) with #define in it, I was able to #include that in the PDE app and it compiled, but this is kinda goofy.

So, I guess I'll go the Makefile route.  I want to build something that uses a couple of OSS libraries, and I may want to tweak the library source and keep it versioned as one big project...and have other devs be able to check it out from github and build/modify w/o a headache...which is why I'm asking these questions.

From what I have seen, the trick is to either use the IDE to add the H and CPP files in the mysketch dir, OR create them first and THEN open mysketch.pde.  The IDE doesn't understand new files created while it is running that it did not create.

Good luck with CMake.  It seems to avoid all of Wiring, and a lot of external code is going to rely on that.  You might just try a regular makefile that still uses all the Arduino code but skips the IDE.  They get posted to the forum occasionally, or you could start with one of my from https://github.com/maniacbug/RF24/blob/master/examples/pingpair/makefile .

lesto

The IDE doesn't support recursive in sketch or library folder
just 2 or 3 days ago i've modified the IDE to support that(in a basic way):
http://code.google.com/p/arduino/issues/detail?id=529
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

westfw

Quote
mandate that library source code be placed in the IDE subdirectory named "libraries"?  Is there some way around this constraint?

You can also put them in <sketchFolder>/libraries/...
(for example ~/Documents/Arduino/libraries (on a mac))

lesto

yes, but you can't put code inside a folder in that folder (for example ~/Documents/Arduino/libraries/lib1/lib2/file.h)
that because arduino IDE look only in the first folder.

with my mod you can :D
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Coding Badly


Works for me...
#include "./lib1/lib2/file.h"

lesto

maybe because it's a library and not a class?
I've never tried with real libraries
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Go Up