Arduino-Makefile icon indicating copy to clipboard operation
Arduino-Makefile copied to clipboard

Not detecting library directory

Open chrisspen opened this issue 7 years ago • 12 comments

I have a number of extra libraries installed in /home/$USER/Arduino/libraries, which I can compile with from inside the Arduino IDE. However, if I try to compile with the makefile, I get the error:

The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH and ARDUINO_LIB_PATH)

Please add support for custom library paths.

I tried setting USER_LIB_PATH, but this doesn't appear to support $USER or ~, and my application doesn't allow hard-coding the username in the path, since it's not a static value.

chrisspen avatar May 28 '17 05:05 chrisspen

Use $(HOME) instead of ~ in Makefiles

See Blink example and issue #320

sej7278 avatar May 28 '17 06:05 sej7278

Ok. In that case, the docs should probably be updated. This explicitly says ~ should work. But you're right, it looks like $(HOME) and $(USER) variables are available.

Is it possible to include relative directories? I have a library in the same directory as my makefile, and to simplify installation and maintainability, I'd prefer to avoid having to copy it into my sketchbook.

However, if I use the setting:

USER_LIB_PATH = .

it still complains that it can't find the library.

chrisspen avatar May 28 '17 18:05 chrisspen

have a look through the other issues, there's a few regarding libraries in the sketch directory, don't think its possible, but paths like "." are never going to work in a Makefile

sej7278 avatar May 28 '17 18:05 sej7278

Is appending multiple paths to USER_LIB_PATH supported? This blog post raves about Arduino-Makefile, claiming it has this ability, but when I use their syntax, e.g.

USER_LIB_PATH = /home/$(USER)/Arduino/libraries
USER_LIB_PATH += $(realpath .)

it causes make to not find any libraries. Whereas each path by itself at least allows make to find the libraries at those paths:

e.g. This partially works (it finds libraries in my sketchbook, but not in the cwd):

USER_LIB_PATH = /home/$(USER)/Arduino/libraries

and this partially works (it finds libraries in my cwd, but not in my sketchbook):

USER_LIB_PATH = $(realpath .)

chrisspen avatar May 28 '17 18:05 chrisspen

fixed the tilde documentation issue in PR #500 now merged

sej7278 avatar Jun 01 '17 20:06 sej7278

My end goal is to allow inclusion of a local ./lib directory, so I don't have to copy every project's libraries into the global sketchbook directory, since that becomes difficult to maintain and inevitably results in conflicts.

Is there any way to currently accomplish this with Arduino-Makefile?

chrisspen avatar Jun 13 '17 15:06 chrisspen

@chrisspen - I did something similar with the bare arduino project

ladislas avatar Jun 14 '17 08:06 ladislas

@chrisspen and actually you'll need to take a look at our fork of the arduino-makefile https://github.com/weareleka/Arduino-Makefile

ladislas avatar Jun 14 '17 09:06 ladislas

Is there no solution for this?

My code looks like:

src/
    lib/
        OtherLibrary/
            some_include.h
            some_other_include.h
    main.ino

My makefile looks like:

BOARD_TAG    = uno
MONITOR_PORT = /dev/ttyACM0
AVRDUDE_OPTS = -v
ARDUINO_LIBS = OtherLibrary
ARDUINO_SKETCHBOOK = $(realpath .)/lib
USER_LIB_PATH = $(realpath .)/lib
include /usr/share/arduino/Arduino.mk

But when I run make, I get the error:

In file included from main.ino:40:0:
some_include.h:3:45: fatal error: OtherLibrary/some_other_include.h: No such file or directory
 #include "OtherLibrary/some_include.h"

Why isn't it finding secondary includes in either the ARDUINO_SKETCHBOOK or USER_LIB_PATH?

I noticed that, for some odd reason, the g++ command outputted doesn't actually include either of these paths as a -I option, and if I manually add that path and call g++ myself, it compiles perfectly.

Am I not configuring arduino-mk correctly, or is this a bug? This seems like a very simple feature that isn't working.

chrisspen avatar Jun 19 '17 00:06 chrisspen

The problem seems to be that arduino-mk completely ignores ARDUINO_SKETCHBOOK, and it doesn't directly include USER_LIB_PATH but instead uses that as a base folder to include the sub-folders that match items in ARDUINO_LIBS. So it's not finding OtherLibrary/some_include.h because it's not using ../OtherLibrary as a search path.

However, why isn't ARDUINO_SKETCHBOOK being used? If I comment out my custom USER_LIB_PATH, then I get the completely nonsensical error message:

 *** The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH, ARDUINO_LIB_PATH and ARDUINO_PLATFORM_LIB_PATH): OtherLibrary

Yes...it'd be found if it checked ARDUINO_SKETCHBOOK. Why isn't that being used as a search path?

chrisspen avatar Jun 19 '17 00:06 chrisspen

@ladislas i thought you wrote some sort of library autodetection script but your fork seems identical to upstream now?

@chrisspen ARDUINO_SKETCHBOOK is not the right place to search for libraries and shouldn't be dynamic between sketches. you probably want to create another variable to achieve what you want.

sej7278 avatar Jun 19 '17 10:06 sej7278

@sej7278 I'm following upstream (you) closely and then reapplying my changes each time.

you have to checkout the auto-lib branch: https://github.com/weareleka/Arduino-Makefile/tree/auto-lib

here are the differences

https://github.com/weareleka/Arduino-Makefile/commit/42c8bdf6368250f199e3a26a5566370e44bb7786

ladislas avatar Jun 19 '17 11:06 ladislas