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

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

Closed
AnnoyingTechnology opened this issue Mar 23, 2019 · 9 comments · May be fixed by #156

Comments

@AnnoyingTechnology
Copy link

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

@AnnoyingTechnology AnnoyingTechnology changed the title Build issue (pkg-config installed, librtlsdr-dev installed) Build fail : undefined reference to `rtlsdr_get_device_count' (pkg-config installed, librtlsdr-dev installed) Mar 23, 2019
@CJHackerz
Copy link

I am also getting same problem

@hopkinskong
Copy link

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

joergsteinkamp added a commit to joergsteinkamp/dump1090 that referenced this issue Jul 30, 2019
@filippog
Copy link

filippog commented Aug 4, 2019

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
Copy link

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
Copy link

Dygear commented May 23, 2020

I went from this error #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 #142 (comment) 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
Copy link

m1zar commented Jul 25, 2020

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
Copy link

Dygear commented Nov 4, 2020

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.

Joseph-Melberg added a commit to Joseph-Melberg/dump1090 that referenced this issue Sep 14, 2021
@iXmerof
Copy link

iXmerof commented Mar 21, 2022

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

@ehp
Copy link

ehp commented May 12, 2023

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

@yuvadm yuvadm closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants