sudar / Arduino-Makefile

Makefile for Arduino sketches. It defines the workflows for compiling code, flashing it to Arduino and even communicating through Serial.

Home Page:http://hardwarefun.com/tutorials/compiling-arduino-sketches-using-makefile

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Library autodetection doesn't work when one library uses another library

matthijskooijman opened this issue · comments

I'm using the ShiftOutX library, which uses the SPI library. Arduino-Makefile fails to detect this case, resulting in a SPI.h not found error message.

Right now the makefile only auto detects the included libraries from the local source files. This was introduced in commit eef7300

I am not sure if we can easily extend this auto detection to libraries as well. Do you have any suggestion for it?

Also as part of issue #45, when we add support for Arduino 1.5.x, we will be implementing Arduino 1.5.x library specification. In this specification the meta file will have the dependency list for libraries.

Till then I guess you might have to manually set ARDUINO_LIBS

Why not just #include <SPI.h> in your main sketch. That would be the easy fix... or does that fail too?

Haven't actually tried that, but I expect it to work. Still, it would be better if it would just work right away, but it's not any kind of priority...

Arduino IDE does not do this either! IIRC you need to place every include you use in the sketch for everything to be located.

Marking it as wontfix, since Arduino IDE doesn't support it.

But I would be happy to merge it if someone can implement it.

shouldn't this be closed as its a wontfix ?

I'd love to work on that! :)

Having to declare in your main sketch all the libs that your libs use is kind of cumbersome and prone to errors...

@sudar @sej7278 where should I start?

@tinyladi,

Nice to know that you are interested in working on this :)

One word of caution though. Since this is something that is not supported by Arduino IDE, it would be nice to have this feature turned off by default and enabled only if a flag is set in the makefile. We would like to maintain compatibility with Arduino IDE as much as possible.

Having said that, you could look at this c3dc56b I tried doing something similar but left it mid-way.

For the record, see also arduino/Arduino#236
There has been some work to support this in the 1.5.x IDE, I expect this will be finished in the near future.

@sudar I'm doing some tests, is it possible to create a test branch in your repo I could PR to so that people could test as well? :)

@matthijskooijman can you tell me how you organize your sources? if you have a github repo, it would be even better.

@ladislas, what are you interested in specifically? I mean I have a sketches folder, containing a libraries folder, containing libraries, but that's pretty standard (and the IDE doesn't allow for a lot of other layouts?)

@matthijskooijman well you can organize your code as you like if you use the Makefile, for example...

But all your libraries are at the same place? something like:

Lib-folder/
    FirstLib/
    SecondLib/
    ThirdLib/

I've actually stopped using this Makefile when I switched to 1.5.x, but I stuck to the classic layout before that as well (always good if you can fall back to the IDE).

Anyway, I have them like you suggest, yes.

@ladislas I have created a new branch called auto-lib to which you can send the pull request.

While you are at it also checkout c3dc56b which I did sometime back.

Thanks for looking into it.

Thank you very much @sudar :) I'll push in tonight or tomorrow.

Right now, auto-detection works. The work around is to use:

ARDUINO_LIBS +=  $(notdir $(wildcard $(USER_LIB_PATH)/*))
# instead of
ARDUINO_LIBS += $(filter $(notdir $(wildcard $(USER_LIB_PATH)/*)), \
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS)))

The problem is that it lists all the libraries, even if they're not used in the current sketch being compiled. But that's just the beginning :)

i was thinking about this just the other day, and as the IDE and the makefile compile all of the core libs even if they're not used, would it really harm to do the same for user libs - i.e. compile everything and leave it to the linker to not link unused ones? so @ladislas one-liner above is enough of a fix....?

@sej7278 well yes and no.

Yes because it seems to be working fine, on my project at least, and if you say that the IDE does the same, it sounds good.

No because the show_config_info will list all the libs available and not only the libs used with the sketch. If it's not an issue, that's alright.

But I'm trying to find a more elegant solution.

yeah i agree its not elegant (and a bit slow the first time) and the IDE doesn't quite do that - it does for the core but not the user libs.

i was thinking of a recursive grep rather than a bunch of sed, but it was a random thought at 3am ;-)

That won't work - if two libraries define functions by the same name, or the same ISR, the linker will barf when they both are linked at the same time (even if not needed, the linker doesn't look at #include lines).

Hello, is this issue still unsolved?

I'm happy to see someone else has forked the project!
That said...
add this to the top of your .ino, and it will work IDE or not: #include <Arduino.h>

After you do that, it will detect everything, At least it does in my trunk, which this fork is based on...

Hi, thanks for your quick reply, I am also happy to be able to use your project. However I'm still struggling with some libraries, but will check out including Arduino.h. The reason may be, that on my Raspi IDE 1.0.5 is instalIed don't know how to update it.

No need to include Arduino.h, read the source, that's already done.

And this isn't a fork of anything from xxxajk, don't feed the troll

While this isn't a fork of my effort, both have a common root, which IIRC is pre-github days.

Yup, first version of this we have history of this was 2010