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.
This is my environment to recompile the rtl-sdr. It is mandatory to have these tools installed on your system:
- Source Versioning – GIT ( http://msysgit.github.io )
- Compiler – MinGW-w64 the GCC for both x64 & x86 Windows (http://mingw-w64.sourceforge.net/ )
- CMake – http://www.cmake.org/
The rtl-sdr compilation uses libusb1.0 library and pthreads. I used the following versions for them:
- libusb1.0 – Following the link present on site libusb.org you can find newer release binary as part of libusbx releases.
- pthreads – I use the pthreads-win32, but the main repository has a broken link, so I used a mirror site to dowload it.
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.
- 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.
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:
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: *** [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: *** [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!
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.
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
Ignore my last comment i got it working i downloaded the wrong mingw
Compiles and installs perfect
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:
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
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.
Would you mind posting the x64 binaries?
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?
With CMake you can generate for different enviroment, you can check here https://cmake.org/cmake/help/v3.4/manual/cmake-generators.7.html#manual:cmake-generators(7)
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.