antirez / dump1090

Dump1090 is a simple Mode S decoder for RTLSDR devices
2.43k stars 1.33k forks source link

Build fail : undefined reference to `rtlsdr_get_device_count' (pkg-config installed, librtlsdr-dev installed) #142

Closed AnnoyingTechnology closed 8 months ago

AnnoyingTechnology commented 5 years ago

Hello,

here it is :

cc -g -o dump1090 dump1090.o anet.o  -L -lrtlsdr -lpthread -lm
/usr/bin/ld: dump1090.o: in function `modesInitRTLSDR':
/home/julien/Downloads/dump1090-master/dump1090.c:340: undefined reference to `rtlsdr_get_device_count'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:348: undefined reference to `rtlsdr_get_device_usb_strings'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:353: undefined reference to `rtlsdr_open'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:360: undefined reference to `rtlsdr_set_tuner_gain_mode'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:372: undefined reference to `rtlsdr_set_tuner_gain'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:377: undefined reference to `rtlsdr_set_freq_correction'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:379: undefined reference to `rtlsdr_set_center_freq'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:380: undefined reference to `rtlsdr_set_sample_rate'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:381: undefined reference to `rtlsdr_reset_buffer'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:383: undefined reference to `rtlsdr_get_tuner_gain'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:378: undefined reference to `rtlsdr_set_agc_mode'
/usr/bin/ld: /home/julien/Downloads/dump1090-master/dump1090.c:368: undefined reference to `rtlsdr_get_tuner_gains'
/usr/bin/ld: dump1090.o: in function `readerThreadEntryPoint':
/home/julien/Downloads/dump1090-master/dump1090.c:460: undefined reference to `rtlsdr_read_async'
/usr/bin/ld: dump1090.o: in function `main':
/home/julien/Downloads/dump1090-master/dump1090.c:2632: undefined reference to `rtlsdr_close'
collect2: error: ld returned 1 exit status
make: *** [Makefile:12: dump1090] Error 1
$ apt search librtlsdr
Sorting... Done
Full Text Search... Done
gr-osmosdr/testing,now 0.1.4-14+b10 amd64 [installed,automatic]
  Gnuradio blocks from the OsmoSDR project

librtlsdr-dev/testing,now 0.6-1 amd64 [installed]
  Software defined radio receiver for Realtek RTL2832U (development)

librtlsdr0/testing,now 0.6-1 amd64 [installed]
  Software defined radio receiver for Realtek RTL2832U (library)

Thanks for your help

CJHackerz commented 5 years ago

I am also getting same problem

hopkinskong commented 5 years ago

The issue is pkg-config generates an empty -L. In my case, do the following:

pkg-config --libs librtlsdr libhackrf libairspy soxr
  1. Copy the output of above command. In my case, it was -L -lrtlsdr -lhackrf -lairspy -lsoxr.
  2. Modify the LDLIBS variable in the Makefile. Substitute the pkg-config expansion ($(shell pkg-config ...)) with above output. Make sure you omit the initial -L, so mine should be -lrtlsdr -lhackrf -lairspy -lsoxr.
  3. Run make
  4. Have fun :)
filippog commented 5 years ago

If the build failure is happening on Debian-based system then it is likely bug #925916 (fixed in testing and unstable). The tl;dr is to have this at the top of /usr/lib/x86_64-linux-gnu/pkgconfig/librtlsdr.pc instead of empty values:

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
DakotaNelson commented 4 years ago

Building on what @filippog said above, on a raspi run pkg-config --libs librtlsdr --debug, which, for me, outputs the location of librtlsdr.pc as /usr/lib/arm-linux-gnueabihf/pkgconfig/librtlsdr.pc - editing it then fixed the issue.

Dygear commented 4 years ago

I went from this error https://github.com/antirez/dump1090/issues/108 to this error here. Even with doing pkg-config --libs librtlsdr --debug I'm still getting the same error. What do I need to edit to make this work?

Per https://github.com/antirez/dump1090/issues/142#issuecomment-487139377 comment ... I should be replacing ... LDLIBS+=$(shell pkg-config --libs librtlsdr) -lpthread -lm with LDLIBS=pkg-config --libs librtlsdr libhackrf libairspy soxr

But I get ...

cc -g -o dump1090 dump1090.o anet.o  pkg-config --libs librtlsdr libhackrf libairspy soxr
cc: error: pkg-config: No such file or directory
cc: error: librtlsdr: No such file or directory
cc: error: libhackrf: No such file or directory
cc: error: libairspy: No such file or directory
cc: error: soxr: No such file or directory
cc: error: unrecognized command line option ‘--libs’
make: *** [Makefile:12: dump1090] Error 1

This is a fresh install of the latest version of raspbian buster. I've issued the following commands in order to get the system into a useable state and I'm using the user pi built into it. But clearly, I'm missing some items.

sudo apt update
sudo apt upgrade
sudo raspi-config 
sudo apt install git cmake libusb-1.0-0.dev
git clone git://git.osmocom.org/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build/
cmake ../
cd ~

git clone https://github.com/antirez/dump1090.git
cd dump1090/
make
sudo apt install librtlsdr-dev
make
pkg-config --libs librtlsdr libhackrf libairspy soxr # Dosen't work.
pkg-config --libs librtlsdr --debug 
make
pkg-config --libs librtlsdr # Outputs -L -lrtlsdr
clear
nano Makefile 
sudo apt install librtlsdr libhackrf libairspy soxr # Doesn't help at all.
make
ls
nano Makefile # Didn't help with the change to LDLIB
make
nano Makefile # Just the rtlsdr as that's what I had.
make

I did some googling and found this stack overflow item usr/bin/ld: cannot find -l with one of the answers saying that I can call ld directly to get information about why it can't find it ... So I did that.

ld -llibrlsdr --verbose produces

[SNIP]
==================================================
attempt to open //usr/local/lib/arm-linux-gnueabihf/liblibrlsdr.so failed
attempt to open //usr/local/lib/arm-linux-gnueabihf/liblibrlsdr.a failed
attempt to open //lib/arm-linux-gnueabihf/liblibrlsdr.so failed
attempt to open //lib/arm-linux-gnueabihf/liblibrlsdr.a failed
attempt to open //usr/lib/arm-linux-gnueabihf/liblibrlsdr.so failed
attempt to open //usr/lib/arm-linux-gnueabihf/liblibrlsdr.a failed
attempt to open //usr/local/lib/liblibrlsdr.so failed
attempt to open //usr/local/lib/liblibrlsdr.a failed
attempt to open //lib/liblibrlsdr.so failed
attempt to open //lib/liblibrlsdr.a failed
attempt to open //usr/lib/liblibrlsdr.so failed
attempt to open //usr/lib/liblibrlsdr.a failed
attempt to open //usr/arm-linux-gnueabihf/lib/liblibrlsdr.so failed
attempt to open //usr/arm-linux-gnueabihf/lib/liblibrlsdr.a failed
ld: cannot find -llibrlsdr

Notice that it's looking for **liblibrlsdr.so**. That's not right.

If you run whereis librtlsdr it shows ...

librtlsdr: /usr/lib/arm-linux-gnueabihf/librtlsdr.so /usr/lib/arm-linux-gnueabihf/librtlsdr.a

So the -l command adds lib for us. If we remove that and just do -lrtlsdr it produces the correct results ... But now gives us a different error ....

cc -g -o dump1090 dump1090.o anet.o  -lrtlsdr -L -lpthread -lm
/usr/bin/ld: dump1090.o: undefined reference to symbol 'pthread_create@@GLIBC_2.4'
/usr/bin/ld: //lib/arm-linux-gnueabihf/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [Makefile:12: dump1090] Error 1

I fixed that last error by doing this to the Makefile ...

dump1090: dump1090.o anet.o
        $(CC) -g -pthread -o dump1090 dump1090.o anet.o $(LDFLAGS) $(LDLIBS)

THIS is now my full make file ...

CFLAGS?=-O2 -g -Wall -W $(shell pkg-config --cflags librtlsdr)
LDLIBS+=-lrtlsdr -L -lpthread -lm
CC?=gcc
PROGNAME=dump1090

all: dump1090

%.o: %.c
        $(CC) $(CFLAGS) -c $<

dump1090: dump1090.o anet.o
        $(CC) -g -pthread -o dump1090 dump1090.o anet.o $(LDFLAGS) $(LDLIBS)

clean:
        rm -f *.o dump1090
m1zar commented 4 years ago

Was using the MalcolRobb/dump1090 version but got this error, finally found that using the version at https://github.com/joergsteinkamp/dump1090, compiles fine. And actually working better than ever! :o)

Hex Mode Sqwk Flight Alt Spd Hdg Lat Long Sig Msgs Ti/

4CAA4F S 27825 7 10 3 50801D S 1160 32950 436 145 7 45 7

Dygear commented 3 years ago

Had to build this again as I moved over to a new system with a new arch. Was surprised that this issue was still open and outstanding, and even more that I had ready commented and fixed the problem. Thanks past me.

iXmerof commented 2 years ago

In 2022 for rpi zero the issue was still present, the @hopkinskong response helped (for lrtlsdr only)

ehp commented 1 year ago

Try install pkg-config package with apt (debian bullseye).