### How to compile librtlsdr on Windows

Librtlsdr is the backend used by most SDR applications compatible with the well-known RTL2832U demodulator. Using librtlsdr, you can get raw I/Q samples from RTL2832U chip, thus turning a cheap TV stick into a software defined radio (SDR).

Librtlsdr source code can be found on GitHub. It compiles easily on Linux hosts using instructions from Osmocom project. Compiling librtsdr on Windows is not that easy, mostly because the only two required libraries (libusb and pthreads) cannot be located using the same methods as on Linux (pkgconfig).

## Install software

To compile librtlsdr on Windows, you need to install the MinGW compiler and the CMake build system. When installing MinGW using the web installer choose mingw32-base package (No MSYS needed, as this Reddit post claims). This should also install pthreads package. Install in the default path: C:/MinGW.

You will need libusb 1.0. Get the Windows binaries. Open the archive and you will see some folders. Copy the entire include folder to C:/MinGW. Go to MinGW32/dll folder and copy libusb-1.0.dll.a to C:/MinGW/lib. From the same folder, copy libusb-1.0.dll to C:/MinGW/bin.

## Edit CMake files

Get a source archive of librtlsdr and extract it to a folder of your choice. Browse that folder. Open CmakeLists.txt with a text editor (one that supports Unix line endings, not Notepad). Go to line 65 (# Find build dependencies) and comment line ~70 (this one: find_package(Threads) – add a # at the beginning of the line). Right there, add the following new lines:

SET(CMAKE_THREAD_LIBS_INIT "-lpthread")
SET(THREADS_FOUND TRUE)

Now, go to the cmake/Modules folder and open FindLibUSB.cmake with a text editor. Locate these lines at the beginning of the file contents:

/usr/include/libusb-1.0
/usr/include/usr/local/include

and add some more, making it look like:

/usr/include/libusb-1.0
/usr/include/usr/local/include
C:/MinGW/include
C:/MinGW/include/libusb-1.0

Save all files and close text editor windows.

## Build library

Open a command prompt in the folder you extracted librtlsdr source (right click in the folder while holding Shift and select Open Command window here).

First of all, make a new folder named build and change to it.

mkdir build
cd build

Set the path of MinGW and CMake:

set PATH=C:\MinGW\bin;C:\Program Files\CMake\bin

Let’s generate makefiles and build:

cmake -G "MinGW Makefiles" ../
mingw32-make

Everything should work. The built executables and DLL are in build/src folder. Executables will not run without pthreadGC-3.dll and libusb-1.0.dll. You need to copy these DLLs from C:/MinGW/bin. Did you get any errors?