Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matthijskooijman opened this issue Jun 27, 2013 · 25 comments
Labels

Comments

@matthijskooijman
Copy link
Contributor

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.

@sudar
Copy link
Owner

sudar commented Jun 28, 2013

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

@xxxajk
Copy link

xxxajk commented Jul 12, 2013

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

@matthijskooijman
Copy link
Contributor Author

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...

@xxxajk
Copy link

xxxajk commented Nov 29, 2013

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

@sudar
Copy link
Owner

sudar commented Dec 1, 2013

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

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

@sej7278
Copy link
Collaborator

sej7278 commented Feb 1, 2014

shouldn't this be closed as its a wontfix ?

@ladislas
Copy link
Contributor

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?

@sudar
Copy link
Owner

sudar commented May 20, 2014

@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.

@matthijskooijman
Copy link
Contributor Author

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.

@ladislas
Copy link
Contributor

@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.

@matthijskooijman
Copy link
Contributor Author

@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?)

@ladislas
Copy link
Contributor

@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/

@matthijskooijman
Copy link
Contributor Author

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.

@sudar
Copy link
Owner

sudar commented Aug 14, 2014

@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.

@ladislas
Copy link
Contributor

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 :)

@sej7278
Copy link
Collaborator

sej7278 commented Aug 14, 2014

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....?

@ladislas
Copy link
Contributor

@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.

@sej7278
Copy link
Collaborator

sej7278 commented Aug 14, 2014

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 ;-)

@matthijskooijman
Copy link
Contributor Author

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).

@pglu
Copy link

pglu commented Feb 22, 2022

Hello, is this issue still unsolved?

@xxxajk
Copy link

xxxajk commented Feb 23, 2022

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...

@pglu
Copy link

pglu commented Mar 2, 2022

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.

@sej7278
Copy link
Collaborator

sej7278 commented Mar 2, 2022

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

@xxxajk
Copy link

xxxajk commented Mar 3, 2022

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

@sej7278
Copy link
Collaborator

sej7278 commented Mar 4, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants