Skip to content

Instantly share code, notes, and snippets.

@icyveins7
Last active September 29, 2021 07:05
Show Gist options
  • Save icyveins7/4234ebb106da3811c331330a1625a629 to your computer and use it in GitHub Desktop.
Save icyveins7/4234ebb106da3811c331330a1625a629 to your computer and use it in GitHub Desktop.
UHD USRP Builds with MinGW64

INCOMPLETE. Unable to Resolve Linker Errors.

Versions Tested

  1. UHD 3.15.0
  2. Boost 1.72.0
  3. msys2-runtime 3.2.0-15 (probably doesn't matter)
  4. msys2-runtime-devel 3.2.0-15 (only used for the header error listed below)
  5. mingw-w64-x86_64-gcc 10.3.0-5

Setup

  1. Get MSYS64 and follow the instructions to the end to download the mingw64 toolchains.
  2. Download your favourite version of Boost source code (1.72 was tested), unzip it, and build it with the Windows Command Prompt by following this link; note that you will have to add the msys64\mingw64\bin to system PATH. Do NOT use the MinGW terminal. During the b2 build step I left out the --build-type=complete as it wasn't necessary for me.
  3. Run CMake (CMake-GUI was a great help for me) on the downloaded UHD source code (I usually download from the github 'Releases' page as a tar.gz rather than cloning). Make a build folder in host (I called mine host\mingwbuild to distinguish it from my other MSVC build folder).
  4. Select MinGW Makefiles as the configuration/compiler toolchain; if it doesn't find your compiler, make sure to add the MinGW64 bin folder to your system PATH e.g. D:\msys64\mingw64\bin. Enable viewing of 'Advanced' entries at the top of the cmake-gui.
  5. Specify the CMake option Boost_INCLUDE_DIR as the path where the boost library --prefix was (it should look like PREFIX/include/boost-1_72 or something similar). Boost_DIR did nothing for me.
  6. For me, the Boost libraries were not found, so I filled them in by myself; I only filled in the Release versions, for example Boost_CHRONO_LIBRARY_RELEASE was set to D:/my_mingw_boost_libraries/lib/libboost_chrono-mgw103-mt-x64-1_72.a. mgw103 should reflect the GCC/G++ version you have installed under mingw (10.3 for me), and the last number 1_72 reflects the boost version. Be sure not to pick the debug versions (they have an extra -d- in the name) for Release, and use the x64 version.
  7. I am not building this with the Python API in mind, so do whatever you wish with it.
  8. Download libusb and link LIBUSB_LIBRARIES to mingw64/dll/libusb-1.0.dll.a or similar (I did not test using the .dll version, but since the boost libraries are all .dll.a I wanted to be consistent). LIBUSB_INCLUDE should point to include/libusb-1.0 or similar.
  9. At this point, the whole project should configure; if any options above don't appear, just reconfigure and fix one missing error at a time. Add an install prefix in CMAKE_INSTALL_PREFIX and Generate.

Make

  1. Open a command prompt (not MSYS/MinGW terminal any more). Navigate to the UHD build folder /mingwbuild and run mingw32-make. Note, you should probably use mingw32-make -j4 if you have more CPU cores (just like make).
  2. Fix the following errors if you see them and re-run the mingw32-make command each time.

Make Errors

  1. WinSock.h already included or something similar. This is due to inclusion of boost/asio.hpp, and was fixed for me by moving this include statement to the top of the file. Files affected were host/lib/deps/rpclib/lib/rpc/server.cc, host/lib/deps/rpclib/lib/rpc/client.cc, host/lib/usrp/mpmd/mpmd_find.cpp, host/lib/usrp/mpmd/mpmd_impl.cpp, host/include/uhd/transport/nirio/rpc/rpc_client.hpp. If you're afraid, just make a copy of them before editing the files.
  2. In addition, the file host/lib/transport/nirio_zero_copy.cpp needed the #include<uhd/transport/nirio_zero_copy.hpp> moved to the top as well, for a similar WinSock.h error.
  3. Missing 'wordexp.h' or something similar. MinGW64 has this header missing, so the easiest way is to open a MSYS2 terminal and install the MSYS2 dev headers via pacman -S msys2-runtime-devel, then going into your msys64\usr\include folder to find wordexp.h, and copying it to the MinGW64 folder at msys64\mingw64\include.
  4. Invalid conversion from boost_native_handle_type to pthread or something similar. In host/lib/utils/thread.cpp, comment out the entire section containing the offending line. NOTE: UNKNOWN WHETHER THIS WILL IMPACT THE EVENTUAL EXECUTABLES. The offending line for me was
    #ifdef HAVE_PTHREAD_SETNAME
    pthread_setname_np(thrd->native_handle(), ....);
    #endif
    
    Interestingly, there were other calls to this function that were okay in other files..
  5. Unable to solve linker issues with AcceptEx..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment