Building and Installing the USRP Open-Source Toolchain (UHD and GNU Radio) on OS X
Application Note Number
|2016-05-01||Michael Dickens||Initial creation|
|2020-02-07||Michael Dickens||OSX updates since creation|
This AN provides a comprehensive step-by-step guide for installing UHD (and GNU Radio) on the OSX operating system (Mac OS X / MacOS X / macOS) -- whether via a package manager or from source.
UHD on OSX
UHD has been compiled and installed on OSX 10.6 ("Snow Leopard") through the macOS 10.15 ("Catalina") running any compatible version of Xcode on all recent and many older Macs. Primary support is for 64-bit Intel-based Macs, running OSX 10.9 or newer using Clang / libc++; secondary support is for OSX 10.6 through 10.8 using Xcode's default GCC / libstdc++ or specially-installed Clang / libc++ (e.g., via MacPorts). There is very little support for getting the background libraries and applications installed on OSX 10.5 or earlier, for 32-bit installs, or for PowerPC based Macs -- though any or all of these might be possible.
X11/XQuartz or Terminal
For the purposes of building and using UHD, you can use Apple's Terminal.app if you so choose, no matter how you install UHD. Other terminal applications such as iTerm2 work well too.
That said, running almost any graphical user interface (GUI) will require downloading and installing X11/XQuartz first. Through OSX 10.8, Apple provided a means to install the X11.app directly, but XQuartz has always been more up to date. Starting in OSX 10.9, Apple no longer provided X11.app. Hence, just use XQuartz from the get-go. Note that unless you experiment with using the Quartz interface to various graphical toolkits (e.g., GTK), you must use X11 as the terminal interface for any GUI applications for UHD and GNU Radio.
Apple provides a full integrated development environment via Xcode, which can be downloaded either via the Mac App store or directly from Apple's Developer area depending on the version of OSX in use. Xcode provides the compilers and related development tools needed to build and execute UHD and its dependencies.
Once Xcode is installed, you must still install the Command Line Tools, which can be accomplished by executing the Xcode.app, then going to Preferences... -> Downloads and making sure Command Line Tools is selected/enabled [feel free to select other downloads too]. You might be able to install the Command Line Tools in a terminal using the command
but this command will not work with every OSX / Xcode combination (e.g., does not work with OSX 10.8 and Xcode 5, but does work with OSX 10.9 and Xcode 5). More recent OSX provides the Command Line Tools via the Mac App Store.
Once the Command Line Tools are installed, UHD and other projects can be installed either from source or, preferably, via a package manager such as MacPorts.
UHD Software Installation on OS X
UHD can be installed via a package manager or from source. For installing via a package manager we cover just via MacPorts; other package managers such as Fink or HomeBrew might provide a means for installed UHD similar to that found in MacPorts. MacPorts tends to be more up-to-date with respect to new releases, which can be both a blessing and a curse since sometimes new released are untested and result in build or runtime errors. MacPorts, HomeBrew, and Fink offer thousands of ready-to-install libraries and applications, and hence they are highly recommended to use instead of installing from source / scratch.
NOTE: We highly recommended that you install all dependencies via the same package manager! When issues arise, the issues are much easier to track down, and updating UHD and any of its dependencies is also much easier.
We recommend using MacPorts and actively support UHD development on OSX via this method. Using MacPorts, the correct hardware device images are automatically installed for you, and there are no post-install tasks. With a single command, you can be up and running in short order.
If you do not already have MacPorts installed, you will need to install it first. If required (such as installing MacPorts from source), follow the MacPorts shell environment changes guide such that MacPorts-installed executables are found before all others. These are the only changes to the shell environment needed to execute any MacPorts-installed executable.
NOTE: Setting any DYLD environment variable (e.g., DYLD_LIBRARY_PATH) for general use is highly discouraged, because doing so, in our experience, leads to problems down the road that are very difficult to diagnose. OSX provides robust means for correcting DYLD-based issues even after dependencies are installed.
Once MacPorts is installed, UHD and all of its dependencies can be installed by executing
sudo port install uhd
This method of installing UHD is actively kept up to date by Ettus Research technical support, and hence is the recommended way to install GNU Radio on OSX. GNU Radio can similarly be installed via
sudo port install gnuradio
The latest developments in UHD and GNU Radio can be installed via
sudo port install uhd-devel sudo port install gnuradio-devel
Please note that the these devel ports, while tested for basic compilation and functionality, are not formal releases and hence should be considered beta software which might contain bugs or even major issues.
There are a number of background libraries and applications that must be installed from source or binary in order to compile or execute UHD; a full list is provided in the UHD build guide. These can be obtained by using a package manager and/or from source.
Many UHD developers first install UHD using MacPorts in order to get all of the necessary background dependencies installed, then remove just UHD via
sudo port uninstall uhd
Compiling UHD from Source
Installing UHD from source follows the standard cmake method, with a few arguments to make sure cmake always finds the Python executable, library, and headers from the same Python install, and uses the desired compiler. First, download the source code either as a release or via GIT.
NOTE: All of the PYTHON defines must point to the same install of Python, otherwise runtime errors are likely to occur.
For example, on OSX 10.14 or 10.15 using Xcode 11 (which provides the Clang compiler suite), MacPorts installed into /opt/local (the default), and for Python 2.7 (as installed by MacPorts), issue the following commands from within the UHD source top-level directory:
$ mkdir build
$ cd build
$ CC=/usr/bin/clang CXX=/usr/bin/clang++ \ cmake -DPYTHON_EXECUTABLE=/opt/local/bin/python2.7 \ -DPYTHON_INCLUDE_DIR=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Headers \ -DPYTHON_LIBRARY=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python ../host
If make succeeds, then you can test the build for errors via
$ make test
To install the build, issue
$ sudo make install
and UHD will be installed into the default prefix, /usr/local .
NOTE: To change the install prefix to /path/to/your/desired/prefix , in the cmake command add the argument -DCMAKE_INSTALL_PREFIX=/path/to/your/desired/prefix -- changing the actual path to that of the desired install prefix.
NOTE: If you want to test where the install will place files, you can set a destination directory that the install prefix is appended to via using the pre-argument DESTDIR. To verify that all files are installed and then uninstalled corrected, we often use the following command
$ DESTDIR=./tmp make install
and then look in the directory ./tmp to verify that all of the desired files are installed into their final destination correctly, starting with the CMAKE_INSTALL_PREFIX. Then, issue the command
$ DESTDIR=./tmp make uninstall
to uninstall from the same directory. Then look in the directory ./tmp to see if any files remain, and if so then fix the CMake scripts to both install and uninstall all of the desired files correctly.
NOTE: Selecting another compiler is as simple as changing the CC and CXX pre-arguments to the cmake command.
Installing GNU Radio on OSX
See the GNU Radio OSX Install guide.