0

I've got a problem with a static library (.a file) I'd like to include into my project: Compilation (with gcc) works well, but linking ends with the library not being found by ld whatever I do:

arm-unknown-linux-gnueabihf-g++ -std=c++11 -ggdb -Wall -Wextra -Wmultichar -O1 -fstack-protector-all -mfpu=neon -mfloat-abi=hard main.o vfd.o relay.o keypad.o receiver.o widgets.o tmc.o database.o sound.o ProceduralTimerTaskAdapter.o cd.o TrafficMessage.o -o autoradio -L $(shell pwd):${HOME}/x-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/arm-linux-gnueabihf:${HOME}/x-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/lib/arm-linux-gnueabihf:${HOME}/x-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib:/usr/lib -Wl,-rpath-link=$(shell pwd):${HOME}/x-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/arm-linux-gnueabihf:${HOME}/x-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/lib/arm-linux-gnueabihf:${HOME}/x-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib -lpthread -lkeystonecomm -lgps -lpigpio -lpigpiod_if2 -lrt -lGeographic -lmk4 -lcsvparser -lasound -lespeak-ng -lmpg123 -lout123 -lPocoFoundation -lPocoUtil -lcdio++ -lcdio -lserial -lkeypad
/home/jacek/x-tools/arm-unknown-linux-gnueabihf/lib/gcc/arm-unknown-linux-gnueabihf/8.3.0/../../../../arm-unknown-linux-gnueabihf/bin/ld.bfd: cannot find -lkeypad
collect2: error: ld returned 1 exit status
make: *** [Makefile:24: autoradio] Fehler 1

The library file in question is named libkeypad.a and resides in the same directory I also call make from: $(shell pwd).

I've also tried out the suggestions stated in How to include static library in makefile, but then I even get a heap of undefined references. Please note that I can't change the library file itself, as I've received it "as is".

3
  • 1
    cannot find -lkeypad The library file in question is named autoradio.a What? Commented yesterday
  • kinda looks like you’re linking the wrong lib name not sure why you call -lkeypad if the file is autoradio.a maybe I’m missing something tho Commented yesterday
  • 1
    I notice -lkeypad is the last argument on the g++ commandline; if your Makefile somehow got CRLF linebreak(s), which is wrong for any Unix including Linux, it would cause that (last-named) library to not be found even when it exists in the/a correct location. Modern versions of file will tell you about this in normal cases, or you can check with sed -n l (ell) or cat -v Commented 11 hours ago

1 Answer 1

0

Your error message is about -lkeypad, and there is no input file with any name related to autoradio on your command line. So please decide first exactly which library files you wish to have included in the link.

The -l option always searches for a file whose name begins with lib, so -lfoo will search for libfoo.a. Thus you cannot use -l to link a file named autoradio.a unless you are willing to rename it. (It looks like some versions of the linker might accept -l:autoradio.a; you'd have to check whether yours does.)

Otherwise, simply include autoradio.a as an input file argument after your other .o files, without using -l. Order matters; see Why does the order in which libraries are linked sometimes cause errors in GCC? for details.

Also, I don't think that -L accepts a list of directories separated by a colon (at least, I can't see any mention of such a feature in the manual). The normal syntax is to give a separate -L option for each directory: -L /path/to/dir1 -L /path/to/dir2 ....

Sign up to request clarification or add additional context in comments.

1 Comment

Copy-paste error, sorry! The library is in fact named libkeypad.a, but the problem remains the same. And: I have already tried out adding the lib in OBJECTS and retried, but no use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.