Page 1 of 1

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

Posted: Thu Oct 18, 2018 2:34 pm
by A.SDR
0
down vote
favorite

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

CC=gcc
CFLAGS= -O0 -c -Wall
LDFLAGS= 

SOURCES=$ fm.c
OBJECTS=$(SOURCES:.c=.o)

EXECUTABLE=fm

all: $(TASKMAP) $(SOURCES) $(EXECUTABLE)

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

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

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

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

Posted: Mon Dec 10, 2018 8:19 pm
by mbroihier
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://git.osmocom.org/rtl-sdr.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 $