Skip to content

Instantly share code, notes, and snippets.

@dmaltsiniotis
Created November 9, 2022 22:45
Show Gist options
  • Save dmaltsiniotis/bb761a9b9a642e9407f14c6f7dfc466a to your computer and use it in GitHub Desktop.
Save dmaltsiniotis/bb761a9b9a642e9407f14c6f7dfc466a to your computer and use it in GitHub Desktop.
How to build hackrf host tools with modern versions of visual studio.

HackRF One Host Tools Build Notes

Download an install Visual Studio (community edition)

You may use any version from Visual Studio 2015 onwards. The slighly different cmake commands for each version of Visual Studio are oulined below, just make sure to use the one that corresponds to your particular installation.

When installing Visual Studio, make sure to select the "Desktop development with C++" workload, which automatically includes the cmake dependecies we'll need later on.

Download and install cmake

Download and install cmake version 3.21 or greater. Make sure to select "Add to the system path" at the end of the installation.

Building with Visual Studio v2015 - v2022

Open a "Visual Studio Command Prompt" from the start menu by navigating to the version of Visual Studio installed, and selecting that option. This is a special command prompt that includes additional 'PATH's to Visual Studio build tools. This is the window in which the actual build will take place.

Create library definition for MSVC to link to

The fftw library needs to be registered (one time operation) with the Visual Studio build system. Navigate to the folder where the dependecy is installed, and run the "lib" command below:

C:\fftw-3.3.5-dll64> lib /machine:x64 /def:libfftw3f-3.def

You should see an output like this:

Use cmake to generate a Visual Studio "solution" file

For Visual Studio 2015

cmake ../ -G "Visual Studio 14 2015 Win64" \
-DLIBUSB_INCLUDE_DIR=c:\libusb-1.0.21\libusb \
-DLIBUSB_LIBRARIES=c:\libusb-1.0.21\MS64\dll\lib\libusb-1.0.lib \
-DTHREADS_PTHREADS_INCLUDE_DIR=c:\pthreads-w32-2-9-1-release\Pre-built.2\include \
-DTHREADS_PTHREADS_WIN32_LIBRARY=c:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\pthreadVC2.lib \
-DFFTW_INCLUDES=C:\fftw-3.3.5-dll64 \
-DFFTW_LIBRARIES=C:\fftw-3.3.5-dll64\libfftw3f-3.lib

For Visual Studio 2019

cmake ../ -G "Visual Studio 16 2019" -A "x64" ^
-DLIBUSB_INCLUDE_DIR=C:\dev\hackrf_libs\libusb-1.0.24\include\libusb-1.0 ^
-DLIBUSB_LIBRARIES=C:\dev\hackrf_libs\libusb-1.0.24\VS2019\MS64\dll\libusb-1.0.lib ^
-DTHREADS_PTHREADS_INCLUDE_DIR=C:\dev\hackrf_libs\pthreads-w32-2-9-1-release\Pre-built.2\include ^
-DTHREADS_PTHREADS_WIN32_LIBRARY=C:\dev\hackrf_libs\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\pthreadVC2.lib ^
-DFFTW_INCLUDES=C:\dev\hackrf_libs\fftw-3.3.5-dll64 ^
-DFFTW_LIBRARIES=C:\dev\hackrf_libs\fftw-3.3.5-dll64\libfftw3f-3.lib

For Visual Studio 2022

cmake ../ -G "Visual Studio 17 2022" -A "x64" ^
-DLIBUSB_INCLUDE_DIR=C:\dev\hackrf_libs\libusb-1.0.24\include\libusb-1.0 ^
-DLIBUSB_LIBRARIES=C:\dev\hackrf_libs\libusb-1.0.24\VS2019\MS64\dll\libusb-1.0.lib ^
-DTHREADS_PTHREADS_INCLUDE_DIR=C:\dev\hackrf_libs\pthreads-w32-2-9-1-release\Pre-built.2\include ^
-DTHREADS_PTHREADS_WIN32_LIBRARY=C:\dev\hackrf_libs\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\pthreadVC2.lib ^
-DFFTW_INCLUDES=C:\dev\hackrf_libs\fftw-3.3.5-dll64 ^
-DFFTW_LIBRARIES=C:\dev\hackrf_libs\fftw-3.3.5-dll64\libfftw3f-3.lib

Use MS Bulid to compile.

msbuild -m HackRF.sln

The -m switch enables parallel builds for faster total build times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment