How can I use the RTL SDR lib for my C application

Show off any of your RTL-SDR or cheap SDR related projects.
Post Reply
Posts: 1
Joined: Thu Oct 18, 2018 2:30 pm

How can I use the RTL SDR lib for my C application

Post by A.SDR » Thu Oct 18, 2018 2:34 pm

down vote

I am trying to create a simple c code to listen to an FM radio channel using an RTL-SDR dongle and as a first step I looked to this rtl-sdr.c file and tried to do the same, for example :

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "rtl-sdr.h"
#include "convenience.h"

int main(int argc, char *argv[])    
    int dev_index = 0;
    dev_index = verbose_device_search("0");
    return 0;
I get the following error undefined reference to 'verbose_device_search' and This is my makefile

Code: Select all

CFLAGS= -O0 -c -Wall

SOURCES=$ fm.c



    $(CC) $(LDFLAGS) $(OBJECTS) -o [email protected] -lm

    $(CC) $(CFLAGS) $< -lm -o [email protected]

    rm -fr $(OBJECTS) $(EXECUTABLE)
can someone put me on track about this problem?

Posts: 1
Joined: Thu Nov 15, 2018 11:45 pm

Re: How can I use the RTL SDR lib for my C application

Post by mbroihier » Mon Dec 10, 2018 8:19 pm

I see this post is old, but I happen to be working on a similar project.

Your specific problem is that you are not referencing a library that you need, libconvenience_static.a.

If you used recent build scripts from git://, this library is built but not installed. You will find it in rtl-sdr/build/src/. On my Raspberry PI, I copied this to /usr/local/lib/ using the following command:

sudo cp -p libconvenience_static.a /usr/local/lib/

In my makefile, I added a LIBS definition following the OBJECTS definition as follows:

LIBS=-lrtlsdr -lconvenience_static

and on the end of the build command, I added a $(LIBS) as follows:
$(CC) $(LDFLAGS) $(OBJECTS) -o [email protected] -lm $(LIBS)

Compiling your code, I got:

[email protected]:~/amdemode $ ./fm
Found 1 device(s):
0: Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
[email protected]:~/amdemod $

Post Reply