How to build RTL-SDR on Windows x64

RTL-SDR compile on windows7

I decided to write a short tutorial where I’m going to explain how I  built the rtlsdr software on windows x64 from source… why? After a crash of my personal linux laptop I had to come back to windows installed on the laptop I use at work. Now I have only it, but I want to continue using rtl-sdr! Unfortunately, on rtl-srd site the “windows” aspect is not much supported and it shows only a link to pre-built version. My nerd-side used this built rtl-sdr  with stupid suspicious (because, at the end, everything works fine) and after some days the nerd-side won and I decided to recompile the rtl-sdr from scratch.

I did not find any tutorial which explains this task and so I decided to write a short tutorial where I’ll explain how I recompiled the rtlsdr software on windows x64 from source.

What is RTL-SDR?

First of all, what is the rtl-sdr? I want to explain it quoting the beautiful site rtl-sdr.com:

RTL-SDR is a very cheap software defined radio that uses a DVB-T TV tuner dongle based on the RTL2832U chipset. With the combined efforts of Antti Palosaari, Eric Fry and Osmocom it was found that the signal I/Q data could be accessed directly, which allowed the DVB-T TV tuner to be converted into a wideband software defined radio via a new software driver.

More information on http://www.rtl-sdr.com/about-rtl-sdr/ or http://sdr.osmocom.org/trac/wiki/rtl-sdr site.

Precondition

This is my environment to recompile the rtl-sdr. It is mandatory to have these tools installed on  your system:

The rtl-sdr compilation uses libusb1.0 library and  pthreads. I used the following versions for them:

Compile

To compile I cloned the source repository:

Z:\>git clone git://git.osmocom.org/rtl-sdr.git
 Cloning into 'rtl-sdr'...
 remote: Counting objects: 1277, done.
 remote: Compressing objects: 100% (371/371), done.
 remote: Total 1277 (delta 931), reused 1220 (delta 898)
 Receiving objects: 100% (1277/1277), 275.08 KiB | 161.00 KiB/s, done.
 Resolving deltas: 100% (931/931), done.

and I built the environment (unzip/ungzip the library) and put it into a directory named libs. Now, the structure of my working dir is:

Z:\>dir /S
 Volume in drive Z is New Volume
 Volume Serial Number is 82D1-DF30

 Directory of Z:\

16/10/2013  12:51    <DIR>          .
16/10/2013  12:51    <DIR>          ..
16/10/2013  12:44    <DIR>          libs
16/10/2013  12:48    <DIR>          rtl-sdr
               0 File(s)              0 bytes

 Directory of Z:\libs

16/10/2013  12:44    <DIR>          .
16/10/2013  12:44    <DIR>          ..
16/10/2013  12:43    <DIR>          libusbx-1.0.17
16/10/2013  12:44    <DIR>          pthreads-w32-2-9-1-release
               0 File(s)              0 bytes
[...]

The next step is to configure cMake to compile the source. On *nix system it exists a useful software called pkg-tool. It resolves all problem for command line library parameters, but on windows I don’t know an equivalent tool. So, I must set manually these parameters on CMake and I used the gui of CMake to set them.

In order:

  • load the command line with mingw64 parameters ( ex C:\…\x64-4.8.1-posix-seh-rev5\mingwbuilds.bat )
  • create a new directory named “build” into “rtl-sdr” folder
  • on folder “build” type the command “cmake-gui”

A new window is opened, it’s the CMake configurator. Into this window I set the flag “advanced” and I  opened the dialog for compiler configuration via “Tools” > “Config”. In this dialog window I set the compilers paths of.

CMake  config with  MinGW-w64
CMake config with MinGW-w64

When you save the configuration, CMake tries to generate the config file but this error occurs:

The C compiler identification is GNU 4.8.1
 Check for working C compiler: C:/Program Files/mingw-builds/x64-4.8.1-posix-seh-rev5/mingw64/bin/x86_64-w64-mingw32-gcc.exe
 Check for working C compiler: C:/Program Files/mingw-builds/x64-4.8.1-posix-seh-rev5/mingw64/bin/x86_64-w64-mingw32-gcc.exe -- works
 Detecting C compiler ABI info
 Detecting C compiler ABI info - done
 Build type not specified: defaulting to release.
 Extracting version information from git describe...
 Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
 libusb-1.0 not found.
 Could NOT find Threads (missing: THREADS_PTHREADS_WIN32_LIBRARY THREADS_PTHREADS_INCLUDE_DIR)
 CMake Error at CMakeLists.txt:67 (message):
 LibUSB 1.0 required to compile rtl-sdr
 Configuring incomplete, errors occurred!

It’s easy, CMake doesn’t find the libraries and we have to indicate them on Name/Value panel. So, I inserted the following information:

CMAKE_GNUtoMS:BOOL=1
PKG_CONFIG_EXECUTABLE:FILEPATH=PKG_CONFIG_EXECUTABLE-NOTFOUND
CMAKE_AR:FILEPATH=C:/Program Files/mingw-builds/x64-4.8.1-posix-seh-rev5/mingw64/bin/ar.exe
CMAKE_STRIP:FILEPATH=C:/Program Files/mingw-builds/x64-4.8.1-posix-seh-rev5/mingw64/bin/strip.exe
CMAKE_MAKE_PROGRAM:FILEPATH=C:/PROGRA~1/MINGW-~1/X64-48~1.1-P/mingw64/bin/mingw32-make.exe
GIT_EXECUTABLE:FILEPATH=C:/Program Files (x86)/Git/cmd/git.exe
CMAKE_USE_RELATIVE_PATHS:BOOL=1
CMAKE_C_STANDARD_LIBRARIES:STRING=-lws2_32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 
LIBUSB_INCLUDE_DIR:PATH=Z:/libs/libusb-1.0.17/include/libusbx-1.0
LIBUSB_LIBRARIES:FILEPATH=Z:/libs/libusb-1.0.17/MinGW64/static/libusb-1.0.a
THREADS_PTHREADS_INCLUDE_DIR:PATH=Z:/libs/pthreads-w32-2-9-1-release/Pre-built.2/include
THREADS_PTHREADS_WIN32_LIBRARY:FILEPATH=Z:/libs/pthreads-w32-2-9-1-release/Pre-built.2/lib/x64/pthreadVC2.lib

That’s all, now we can run the configure and generate command to build all make files. After closing the cmake-gui on command line,  we can start the compilation and everything is ok!

Is it really everything ok?

Emmh… in my checkout (trunk) I started the compilation with the command mingw32-make.exe but I had this problem:

Compilation of rtl-sdr
Compilation of rtl-sdr

I asked info on mailing list for this error:

..\..\src\rtl_tcp.c: In function 'gettimeofday':
..\..\src\rtl_tcp.c:112:10: error: invalid suffix "Ui64" on integer constant
   tmp -= 11644473600000000Ui64;
          ^
src\CMakeFiles\rtl_tcp.dir\build.make:57: recipe for target 'src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.obj' failed
mingw32-make.exe[2]: *** [src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.obj] Error 1
CMakeFiles\Makefile2:319: recipe for target 'src/CMakeFiles/rtl_tcp.dir/all' failed
mingw32-make.exe[1]: *** [src/CMakeFiles/rtl_tcp.dir/all] Error 2
Makefile:115: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2

and the mailing list helped me to solve immediately the problem, I’ll quote the answer below:

It looks like the “i64” suffix is specific to Microsoft VC++.  I guess since you’re compiling for Windows it’s assumed you’ll be using the MS compiler.  Try changing the “Ui64” at the end of the number to the standard “ULL” instead and see if that lets you finish compiling.

So, I replaced Ui64 with ULL and now really everything compiles!

9 thoughts on “How to build RTL-SDR on Windows x64”

  1. Hi Allessandro,

    Thanks for providing this tutorial ! I has allowed me, with little prior experience, to compile my own a 64-bit version of RTL_SDR for radio-astronomy.

    I wonder if you can show me how to compile for 32-bit instead of 64-bit.

    Best Regards

    Steve Olney

  2. I’m using x86 i have downloaded and installed everything you said

    when i run mingw32-make i’m getting an error, This is my output

    C:UsersDannyDesktoprtl-sdrrtl-sdrbuild&gt;mingw32-make.exe
    [  4%] Building C object src/CMakeFiles/rtlsdr_shared.dir/librtlsdr.c.obj
    [  9%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_e4k.c.obj
    [ 14%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0012.c.obj
    [ 19%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0013.c.obj
    [ 23%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc2580.c.obj
    [ 28%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_r82xx.c.obj
    Linking C shared library librtlsdr.dll
    C:UsersDannyDesktoprtl-sdrlibslibusbxMinGW32staticlibusb-1.0.a(libusb_1
    _0_la-core.o):core.c:(.text+0xd3): undefined reference to `__ms_vsnprintf'
    C:UsersDannyDesktoprtl-sdrlibslibusbxMinGW32staticlibusb-1.0.a(libusb_1
    _0_la-core.o):core.c:(.text+0x413): undefined reference to `__ms_vsnprintf'
    c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:UsersD
    annyDesktoprtl-sdrlibslibusbxMinGW32staticlibusb-1.0.a(libusb_1_0_la-core
    .o): bad reloc address 0x100 in section `.rdata'
    collect2.exe: error: ld returned 1 exit status
    srcCMakeFilesrtlsdr_shared.dirbuild.make:217: recipe for target 'src/librtlsd
    r.dll' failed
    mingw32-make.exe[2]: *** [src/librtlsdr.dll] Error 1
    CMakeFilesMakefile2:469: recipe for target 'src/CMakeFiles/rtlsdr_shared.dir/al
    l' failed
    mingw32-make.exe[1]: *** [src/CMakeFiles/rtlsdr_shared.dir/all] Error 2
    Makefile:116: recipe for target 'all' failed
    mingw32-make.exe: *** [all] Error 2
    
  3. Ignore my last comment i got it working i downloaded the wrong mingw

    Build type not specified: defaulting to release.
    Extracting version information from git describe...
    Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
    Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON
    Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable
    Building for version: v0.5.3-6-gd447 / 0.5git
    Using install prefix: C:/Program Files/rtlsdr
    Configuring done
    Generating done
    

    Compiles and installs perfect

  4. Thank you for the instructions, but I had a slightly different setup work for me. The exact config above gave link errors. After some experimentation I got the following combination to generate the applications and dlls:
    ../libs/libusb-1.0.19-rc1/include/libusb-1.0
    ../libs/libusb-1.0.19-rc1/MinGW32/static/libusb-1.0.a
    ../libs/pthreads-w32-2-9-1/Pre-built.2/include
    ../libs/pthreads-w32-2-9-1/Pre-built.2/lib/x86/pthreadVC2.lib
    UNCHECK: USE_RELATIVE_PATHS
    UNCHECK: CMAKE_GNUtoMS
    Note that I had to use libusb instead of libusbX. The latter didn’t work for me. Also I had to use the pthreads library in the x86 subdirectory as opposed to the x64 subdirectory. On the upside I don’t get the Microsoft VC++ error.
    This was done with Mingw-w64

    1. Also, I should add that I ran cmake_gui from the rtl-sdr directory, but mingw32-make.exe from the rtl-sdr/build subdirectory. They make that suggestion somewhere else on the web and in my case it works.

  5. I want to develope my owm application with RTL-SDR written in C++ for windows system.
    Using for example VSC++.
    What have I to do?
    Regards

  6. A few changes I had to make to compile on my system:
    1) C compiler must be set to GCC not G++ (like the image shows)
    2) LIBUSB_LIBRARIES must reference MinGW32 not MinGW64
    3) Set CMAKE_INSTALL_PREFIX to same as build directory (not sure if this is required or not)
    4) I had to remove “inline” from a few function declarations — FIX_MPY in rt_power.c and preamble, single_manchester in rtl_adsb.c

    I have little experience with this build environment, so I really have no idea why.

Leave a Reply