How to compile librtlsdr on Windows

 Posted by:   Posted on:   Updated on:  2017-12-16T17:36:02Z

How to build librtlsdr from source on Windows hosts using MinGW and CMake.

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

Compile librtlsdr on Windows - cmd screenshot

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.

Download and install CMake. Install it with the default options.

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:


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:


and add some more, making it look like:

/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" ../

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?


  1. [ 20%] Built target rtlsdr_shared
    [ 26%] Built target convenience_static
    [ 47%] Built target rtlsdr_static
    [ 52%] Built target libgetopt_static
    [ 55%] Linking C executable rtl_sdr.exe
    c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
    collect2.exe: error: ld returned 1 exit status
    src\CMakeFiles\rtl_sdr.dir\build.make:90: recipe for target 'src/rtl_sdr.exe' failed
    mingw32-make[2]: *** [src/rtl_sdr.exe] Error 1
    CMakeFiles\Makefile2:311: recipe for target 'src/CMakeFiles/rtl_sdr.dir/all' failed
    mingw32-make[1]: *** [src/CMakeFiles/rtl_sdr.dir/all] Error 2
    Makefile:128: recipe for target 'all' failed
    mingw32-make: *** [all] Error 2

    i got this error while installing it on windows 10 X64

  2. This comment has been removed by the author.

  3. When you download and install MinGW it won't install pthreads library, so you should install it by yourself, and if you have not internet connection it will be hell)))

  4. I'm trying to compile librtlsdr-development with these instructions
    Is that possible?

    May I enquire what versions of libusb these instructions work with
    When I click the download link I get libusb-1.0.21 (1).7z
    Thanking you in advance

    1. Yes, it should be possible. At the moment I'm trying to use MSYS2, but it seems to fail with CMake.

    2. Hmm I've tried so many variations without luck. But I now have a version that after modification compiles using only VS 2019, just using the inbuilt c++. Would be interesting if it works trouble free for anyone else


Please read the comments policy before publishing your comment.