greatscottgadgets / hackrf

low cost software radio platform
https://greatscottgadgets.com/hackrf/
GNU General Public License v2.0
6.57k stars 1.53k forks source link

How to build host software on Windows #1107

Open stevewillson opened 2 years ago

stevewillson commented 2 years ago

I'm writing these instructions to document a successful build process of the host software on Windows 11 using MSYS2. I had trouble following the build instructions on the README

How to build host software on Windows:

Prerequisites:

MSYS2 Packages:

Open MSYS2 MinGW x64 from the Start Menu

Update the package repository $ pacman -Syu

Install the required packages $ pacman -Syu --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-libusb mingw-w64-x86_64-fftw git

Clone the hackrf repository

$ git clone https://github.com/greatscottgadgets/hackrf.git

$ cd hackrf

$ mkdir host/build

$ cd host/build

Create the Makefiles $ ${MINGW_PREFIX}/bin/cmake ../ -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/lib -DFFTW_LIBRARIES=/lib

$ make

$ make install (may require running MSYS2 as Administrator)

This will install the hackrf host tools to: C:\Program Files (x86)\HackRF\bin

When I tried to execute hackrf_info.exe from that directory, I had to add the following folder to the Windows Path Environment Variable to locate the DLLs. Add the following entry to the Path:

Open a Windows CMD Shell and execute: C:\Program Files (x86)\HackRF\bin\hackrf_info.exe

If a HackRF board is connected, the information should be displayed.

martinling commented 2 years ago

Thanks for writing this up! I'm reopening this to remind us to update the documentation.

corcorj commented 2 years ago

After I get past moving to the host/build directory step and try to create the make files with the shown code i get an output like this:

MSYS ~/hackrf/host/build $ ${MINGW_PREFIX}/bin/cmake ../ -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/lib -DFFTW_LIBRARIES=/lib bash: /bin/cmake: No such file or directory

I assume it has something to do with the path and variables however I have: C:\Program Files\CMake\bin , C:\Program Files\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin , AND C:\opencv\build\install\x64\mingw\bin

In my PATH environment could someone help me out with this?

stevewillson commented 2 years ago

Put a $ before {MINGW_PREFIX}. It should be ${MINGW_PREFIX}.

Full line: ${MINGW_PREFIX}/bin/cmake ../ -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/lib -DFFTW_LIBRARIES=/lib

When I start MSYS2 in "MinGW x64 mode" from the Windows Start Menu ("MSYS2 MinGW x64") the MINGW_PREFIX environment variable is set to /mingw64

$ echo $MINGW_PREFIX
/mingw64

I had to include this because there are 2 versions of cmake on my MSYS2 installation: /mingw64/bin/cmake and /usr/bin/cmake

$ /usr/bin/cmake -version
cmake version 3.22.1

$ /mingw64/bin/cmake -version
cmake version 3.23.2

The /usr/bin/cmake version (3.22.1) doesn't support the -G "MSYS Makesfiles" generator option, but the cmake version 3.23.2 supports the "MSYS Makefiles" generator option.

To see which generators are supported by cmake, use cmake -h and at the bottom of the output text, supported generators are displayed.

$ /mingw64/bin/cmake -h
----- OUTPUT TRUNCATED -----
Generators

The following generators are available on this platform (* marks default):
----- OUTPUT TRUNCATED -----
  MSYS Makefiles               = Generates MSYS makefiles.
  MinGW Makefiles              = Generates a make file for use with
                                 mingw32-make.
  Green Hills MULTI            = Generates Green Hills MULTI files
                                 (experimental, work-in-progress).
  Unix Makefiles               = Generates standard UNIX makefiles.
----- OUTPUT TRUNCATED -----
corcorj commented 2 years ago

thank you for that clarification that helped me overcome that specific line of code however now when I moved onto the make and make install commands I got errors..

It looks like I didn't have libusb.h in the right directory on the make and make install commands but when I generated the make file with the command I was missing the $ with, looking at the output it does show that I have libusb installed correctly for that command to work correctly and output a make file or build files to : C:/msys64/home/jcorc/hackrf/host/build.

I installed libusb with Cygwin and I also followed the link in the documentation listing it as a prereq to be able to install hackRF Software, however the download link downloaded a linux file and i am on windows the name of that file was: libusbx-1.0.18 (1).tar.bz2

Is the Cygwin install of libusb not sufficent for the needs of the hackRF tools installation? I googled more windows friendly libusb installers and ran them as well but these errors I am getting are leading me to believe that a file or directory wasn't created for which the make install command was looking for..

Any thoughts or ideas as to why I am getting the errors I got when running the make and make install commands outputed below??

Thank you

Here is my commandline output:

jcorc@Beast MINGW64 ~

cd hackrf

jcorc@Beast MINGW64 ~/hackrf

cd host/build

jcorc@Beast MINGW64 ~/hackrf/host/build

/usr/bin/cmake -version

bash: /usr/bin/cmake: No such file or directory

jcorc@Beast MINGW64 ~/hackrf/host/build

/mingw64/bin/cmake -version

cmake version 3.23.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

jcorc@Beast MINGW64 ~/hackrf/host/build

/mingw64/bin/cmake -h

Usage

cmake [options] cmake [options] cmake [options] -S -B

Specify a source directory to (re-)generate a build system for it in the current working directory. Specify an existing build directory to re-generate its build system.

Options -S = Explicitly specify a source directory. -B = Explicitly specify a build directory. -C = Pre-load a script to populate the cache. -D [:]= = Create or update a cmake cache entry. -U = Remove matching entries from CMake cache. -G = Specify a build system generator. -T = Specify toolset name if supported by generator. -A = Specify platform name if supported by generator. --toolchain = Specify toolchain file [CMAKE_TOOLCHAIN_FILE]. --install-prefix = Specify install directory [CMAKE_INSTALL_PREFIX]. -Wdev = Enable developer warnings. -Wno-dev = Suppress developer warnings. -Werror=dev = Make developer warnings errors. -Wno-error=dev = Make developer warnings not errors. -Wdeprecated = Enable deprecation warnings. -Wno-deprecated = Suppress deprecation warnings. -Werror=deprecated = Make deprecated macro and function warnings errors. -Wno-error=deprecated = Make deprecated macro and function warnings not errors. --preset ,--preset= = Specify a configure preset. --list-presets = List available presets. -E = CMake command mode. -L[A][H] = List non-advanced cached variables. --build

= Build a CMake-generated project binary tree. --install = Install a CMake-generated project binary tree. --open = Open generated project in the associated application. -N = View mode only. -P = Process script mode. --find-package = Legacy pkg-config like mode. Do not use. --graphviz=[file] = Generate graphviz of dependencies, see CMakeGraphVizOptions.cmake for more. --system-information [file] = Dump information about this system. --log-level=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE> = Set the verbosity of messages from CMake files. --loglevel is also accepted for backward compatibility reasons. --log-context = Prepend log messages with context, if given --debug-trycompile = Do not delete the try_compile build tree. Only useful on one try_compile at a time. --debug-output = Put cmake in a debug mode. --debug-find = Put cmake find in a debug mode. --debug-find-pkg=[,...] = Limit cmake debug-find to the comma-separated list of packages --debug-find-var=[,...] = Limit cmake debug-find to the comma-separated list of result variables --trace = Put cmake in trace mode. --trace-expand = Put cmake in trace mode with variable expansion. --trace-format=<human|json-v1> = Set the output format of the trace. --trace-source= = Trace only this CMake file/module. Multiple options allowed. --trace-redirect= = Redirect trace output to a file instead of stderr. --warn-uninitialized = Warn about uninitialized values. --no-warn-unused-cli = Don't warn about command line options. --check-system-vars = Find problems with variable usage in system files. --profiling-format= = Output data for profiling CMake scripts. Supported formats: google-trace --profiling-output= = Select an output path for the profiling data enabled through --profiling-format. --help,-help,-usage,-h,-H,/? = Print usage information and exit. --version,-version,/V [] = Print version number and exit. --help-full [] = Print all help manuals and exit. --help-manual [] = Print one help manual and exit. --help-manual-list [] = List help manuals available and exit. --help-command [] = Print help for one command and exit. --help-command-list [] = List commands with help available and exit. --help-commands [] = Print cmake-commands manual and exit. --help-module [] = Print help for one module and exit. --help-module-list [] = List modules with help available and exit. --help-modules [] = Print cmake-modules manual and exit. --help-policy [] = Print help for one policy and exit. --help-policy-list [] = List policies with help available and exit. --help-policies [] = Print cmake-policies manual and exit. --help-property [] = Print help for one property and exit. --help-property-list [] = List properties with help available and exit. --help-properties [] = Print cmake-properties manual and exit. --help-variable var [] = Print help for one variable and exit. --help-variable-list [] = List variables with help available and exit. --help-variables [] = Print cmake-variables manual and exit.

Generators

The following generators are available on this platform (* marks default): Visual Studio 17 2022 = Generates Visual Studio 2022 project files. Use -A option to specify architecture. Visual Studio 16 2019 = Generates Visual Studio 2019 project files. Use -A option to specify architecture. Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 10 2010 [arch] = Deprecated. Generates Visual Studio 2010 project files. Optional [arch] can be "Win64" or "IA64". Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files. Optional [arch] can be "Win64" or "IA64". Borland Makefiles = Generates Borland makefiles. NMake Makefiles = Generates NMake makefiles. NMake Makefiles JOM = Generates JOM makefiles. MSYS Makefiles = Generates MSYS makefiles. MinGW Makefiles = Generates a make file for use with mingw32-make. Green Hills MULTI = Generates Green Hills MULTI files (experimental, work-in-progress). Unix Makefiles = Generates standard UNIX makefiles.

  • Ninja = Generates build.ninja files. Ninja Multi-Config = Generates build-.ninja files. Watcom WMake = Generates Watcom WMake makefiles. CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files. CodeBlocks - NMake Makefiles = Generates CodeBlocks project files. CodeBlocks - NMake Makefiles JOM = Generates CodeBlocks project files. CodeBlocks - Ninja = Generates CodeBlocks project files. CodeBlocks - Unix Makefiles = Generates CodeBlocks project files. CodeLite - MinGW Makefiles = Generates CodeLite project files. CodeLite - NMake Makefiles = Generates CodeLite project files. CodeLite - Ninja = Generates CodeLite project files. CodeLite - Unix Makefiles = Generates CodeLite project files. Eclipse CDT4 - NMake Makefiles = Generates Eclipse CDT 4.0 project files. Eclipse CDT4 - MinGW Makefiles = Generates Eclipse CDT 4.0 project files. Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files. Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files. Kate - MinGW Makefiles = Generates Kate project files. Kate - NMake Makefiles = Generates Kate project files. Kate - Ninja = Generates Kate project files. Kate - Unix Makefiles = Generates Kate project files. Sublime Text 2 - MinGW Makefiles = Generates Sublime Text 2 project files. Sublime Text 2 - NMake Makefiles = Generates Sublime Text 2 project files. Sublime Text 2 - Ninja = Generates Sublime Text 2 project files. Sublime Text 2 - Unix Makefiles = Generates Sublime Text 2 project files.

jcorc@Beast MINGW64 ~/hackrf/host/build

${MINGW_PREFIX}/bin/cmake ../ -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/lib -DFFTW_LIBRARIES=/lib

CMake Deprecation Warning at CMakeLists.txt:3 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

-- The C compiler identification is GNU 12.1.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped -- Detecting C compile features -- Detecting C compile features - done CMake Deprecation Warning at libhackrf/CMakeLists.txt:24 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

CMake Warning (dev) at C:/msys64/mingw64/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:438 (message): The package name passed to find_package_handle_standard_args (LIBUSB) does not match the name of the calling package (USB1). This can lead to problems in calling code that expects find_package result variables (e.g., _FOUND) to follow a certain pattern. Call Stack (most recent call first): cmake/modules/FindUSB1.cmake:39 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) libhackrf/CMakeLists.txt:48 (find_package) This warning is for project developers. Use -Wno-dev to suppress it.

-- Found LIBUSB: C:/msys64/mingw64/lib/libusb-1.0.dll.a -- Looking for include file pthread.h -- Looking for include file pthread.h - found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE CMake Deprecation Warning at hackrf-tools/CMakeLists.txt:24 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

-- Found FFTW: C:/msys64/lib -- Configuring done -- Generating done -- Build files have been written to: C:/msys64/home/jcorc/hackrf/host/build

jcorc@Beast MINGW64 ~/hackrf/host/build

make

[ 5%] Building C object libhackrf/src/CMakeFiles/hackrf.dir/hackrf.c.obj C:/msys64/home/jcorc/hackrf/host/libhackrf/src/hackrf.c:31:10: fatal error: libusb.h: No such file or directory 31 | #include | ^~~~~~ compilation terminated. make[2]: [libhackrf/src/CMakeFiles/hackrf.dir/build.make:76: libhackrf/src/CMakeFiles/hackrf.dir/hackrf.c.obj] Error 1 make[1]: [CMakeFiles/Makefile2:189: libhackrf/src/CMakeFiles/hackrf.dir/all] Error 2 make: *** [Makefile:136: all] Error 2

jcorc@Beast MINGW64 ~/hackrf/host/build

make install

[ 5%] Building C object libhackrf/src/CMakeFiles/hackrf.dir/hackrf.c.obj C:/msys64/home/jcorc/hackrf/host/libhackrf/src/hackrf.c:31:10: fatal error: libusb.h: No such file or directory 31 | #include | ^~~~~~ compilation terminated. make[2]: [libhackrf/src/CMakeFiles/hackrf.dir/build.make:76: libhackrf/src/CMakeFiles/hackrf.dir/hackrf.c.obj] Error 1 make[1]: [CMakeFiles/Makefile2:189: libhackrf/src/CMakeFiles/hackrf.dir/all] Error 2 make: *** [Makefile:136: all] Error 2

stevewillson commented 2 years ago

I'm not sure about using cygwin to install the libusb files.

I am using MSYS2 and used pacman to install the package mingw-w64-x86_64-libusb to provide the libusb files.

Here is a listing of the files that the package mingw-w64-x86_64-libusb provides:

$ pacman -Ql PACKAGE - list the files owned by the queried package (from $ pacman -Q -h)

$ pacman -Ql mingw-w64-x86_64-libusb
mingw-w64-x86_64-libusb /mingw64/
mingw-w64-x86_64-libusb /mingw64/bin/
mingw-w64-x86_64-libusb /mingw64/bin/libusb-1.0.dll
mingw-w64-x86_64-libusb /mingw64/include/
mingw-w64-x86_64-libusb /mingw64/include/libusb-1.0/
mingw-w64-x86_64-libusb /mingw64/include/libusb-1.0/libusb.h
mingw-w64-x86_64-libusb /mingw64/lib/
mingw-w64-x86_64-libusb /mingw64/lib/libusb-1.0.a
mingw-w64-x86_64-libusb /mingw64/lib/libusb-1.0.dll.a
mingw-w64-x86_64-libusb /mingw64/lib/pkgconfig/
mingw-w64-x86_64-libusb /mingw64/lib/pkgconfig/libusb-1.0.pc
mingw-w64-x86_64-libusb /mingw64/share/
mingw-w64-x86_64-libusb /mingw64/share/licenses/
mingw-w64-x86_64-libusb /mingw64/share/licenses/libusb/
mingw-w64-x86_64-libusb /mingw64/share/licenses/libusb/COPYING

The file libusb.h is located at: /mingw64/include/libusb-1.0/libusb.h

Do you have libusb.h at that same location?

To locate libusb.h use the locate command: $ locate libusb.h, but before doing that, update the local file index using $ updatedb

t812206236 commented 1 year ago

you use -DLIBUSB_INCLUDE_DIR to include lib path? that makes no sense,you should include header

joedwardson commented 7 months ago

For anyone that encounter [libusb ](ibusb.h: No such file or directory) in the makestep. Edit the import in source code helped for me: Open File-> C:\msys64\home\\hackrf\host\libhackrf\src\hackrf.c Change line #include <libusb.h> To #include <libusb-1.0/libusb.h>

With this fix I got passed this problem:

libusb.h: No such file or directory
31 | #include <libusb.h>
| ^~~~~~~~~~

I should mention I dont know if this is a valid fix, just wanted to post here in case someone else got stuck and want a quick fix.

shad0w82 commented 4 months ago

For anyone that encounter [libusb ](ibusb.h: No such file or directory) in the makestep. Edit the import in source code helped for me: Open File-> C:\msys64\home\hackrf\host\libhackrf\src\hackrf.c Change line #include <libusb.h> To #include <libusb-1.0/libusb.h>

With this fix I got passed this problem:

libusb.h: No such file or directory
31 | #include <libusb.h>
| ^~~~~~~~~~

I should mention I dont know if this is a valid fix, just wanted to post here in case someone else got stuck and want a quick fix.

The correct fix to overcome this problem, without modifying the source code, should be calling this as a CMAKE command: ${MINGW_PREFIX}/bin/cmake ../ -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=${MINGW_PREFIX}/include/libusb-1.0 -DFFTW_LIBRARIES=/lib