MacInstall: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
mNo edit summary
(add a note about DYLD_LIBRARY_PATH)
Line 6: Line 6:


Running almost any GNU Radio graphical interface (GUI) will require [http://xquartz.macosforge.org/landing/ downloading and installing X11/XQuartz] first. Through OSX 10.8, Apple provided a means to install X11.app, but XQuartz has always been more up to date and hence is recommended for use. Staring in OSX 10.9, Apple no longer provides a full working version of 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.app as the terminal interface for GNU Radio GUI applications including GRC, the GNU Radio Companion.
Running almost any GNU Radio graphical interface (GUI) will require [http://xquartz.macosforge.org/landing/ downloading and installing X11/XQuartz] first. Through OSX 10.8, Apple provided a means to install X11.app, but XQuartz has always been more up to date and hence is recommended for use. Staring in OSX 10.9, Apple no longer provides a full working version of 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.app as the terminal interface for GNU Radio GUI applications including GRC, the GNU Radio Companion.
== A note about DYLD_LIBRARY_PATH and other DYLD environment variables ==
On MacOSX / macOS, the library search path is set primarily by the environment variable DYLD_LIBRARY_PATH (and the few other DYLD variables). Because of the way the OSX dynamic library loader works, this variable works differently than the LD_LIBRARY_PATH on Linux. Its primary purpose is in finding libraries in a local path, such as when testing software before installing it (we use it in ''make test'' in GR), or inside an application. <b>We strongly recommend against setting this variable globally as is typically done with Linux and LD_LIBRARY_PATH.</b> Setting any DYLD environment variable 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.


== Via MacPorts (recommended) ==
== Via MacPorts (recommended) ==


If you do not already have MacPorts installed, you will need to [https://www.macports.org/install.php install it] first. Make sure to follow the [https://guide.macports.org/chunked/installing.shell.html MacPorts shell environment changes] needed 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! 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.
If you do not already have MacPorts installed, you will need to [https://www.macports.org/install.php install it] first. Make sure to follow the [https://guide.macports.org/chunked/installing.shell.html MacPorts shell environment changes] needed 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!


Once MacPorts is installed, GNU Radio and all of its dependencies can be installed by executing
Once MacPorts is installed, GNU Radio and all of its dependencies can be installed by executing

Revision as of 15:08, 27 January 2020

Installing GNU Radio on Mac OS X

GNU Radio has been compiled and installed on Mac OS X 10.4 ("Tiger") through 10.10 ("Yosemite") running any compatible version of Xcode on all recent and many older Macs -- whether Intel or PPC. There is very little support for getting the background libraries and applications installed on Mac OS X 10.5 or earlier, nor 32-bit Intel or any PPC, though all of these should be possible. Primary support is for 64-bit Intel-based Macs running 10.6 or newer.

Prerequisite: X11.app, recommended via XQuartz

Running almost any GNU Radio graphical interface (GUI) will require downloading and installing X11/XQuartz first. Through OSX 10.8, Apple provided a means to install X11.app, but XQuartz has always been more up to date and hence is recommended for use. Staring in OSX 10.9, Apple no longer provides a full working version of 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.app as the terminal interface for GNU Radio GUI applications including GRC, the GNU Radio Companion.

A note about DYLD_LIBRARY_PATH and other DYLD environment variables

On MacOSX / macOS, the library search path is set primarily by the environment variable DYLD_LIBRARY_PATH (and the few other DYLD variables). Because of the way the OSX dynamic library loader works, this variable works differently than the LD_LIBRARY_PATH on Linux. Its primary purpose is in finding libraries in a local path, such as when testing software before installing it (we use it in make test in GR), or inside an application. We strongly recommend against setting this variable globally as is typically done with Linux and LD_LIBRARY_PATH. Setting any DYLD environment variable 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.

Via MacPorts (recommended)

If you do not already have MacPorts installed, you will need to install it first. Make sure to follow the MacPorts shell environment changes needed 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!

Once MacPorts is installed, GNU Radio and all of its dependencies can be installed by executing

sudo port install gnuradio

This method of installing GNU Radio is actively kept up to date by Michael Dickens, and hence is the recommended way to install GNU Radio on Mac OS X.

The latest developments in GNU Radio can be installed via

sudo port install gnuradio-devel

Please note that the gnuradio-devel port, while tested for basic compilation and functionality, is not a formal release and hence should be considered beta software which might contain bugs or major issues.

Other Package Managers

Fink and HomeBrew might provide a simple way to install GNU Radio; they are untested (as of early 2014).

From Source

Background Dependencies

There are a number of background libraries and applications that must be installed from source or binary in order to compile or execute GNU Radio. These can be obtained by using MacPorts, Fink, HomeBrew, and/or from source / scratch. 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, they are much easier to track down, and your updating to newer versions is also much easier.

Many GNU Radio developers first install GNU Radio using MacPorts in order to get all of the necessary background dependencies installed, then remove just GNU Radio via

sudo port uninstall gnuradio

Compiling GNU Radio from Source

Installing GNU Radio from source follows the standard build guide, with a change to the cmake command such that it always finds the correct version of Python, uses the desired compiler, and finds Sphinx.

For example, using Xcode 5 or later's Apple GCC (llvm flavor), MacPorts installed into /opt/local (the default), and for Python 2.7 (as installed by MacPorts), issue the following commands from within the GNU Radio source directory:

$ mkdir build
$ cd build
$ CC=/usr/bin/llvm-gcc CXX=/usr/bin/llvm-g++ 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 -DSPHINX_EXECUTABLE=/opt/local/bin/rst2html-2.7.py -DGR_PYTHON_DIR=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages ..
$ make

If make succeeds, then you can test the build for errors via

$ make test

To install the build, issue

$ sudo make install

Selecting another compiler is as simple as changing the CC and CXX pre-arguments to the cmake command. Note that all of the -DPYTHON* defines must point to the same install of Python, otherwise runtime errors are likely to occur. GR_PYTHON_DIR sets the location into which GNU Radio's Python and SWIG files are to be installed.

By default, the location where cmake built projects will be installed is /usr/local. To change this location, add -DCMAKE_INSTALL_PREFIX=/path/to/new/location to the cmake command line, substituting in the actual desired path for /path/to/new/location. For example, to install into /opt/local, use -DCMAKE_INSTALL_PREFIX=/opt/local. Although we do not generally recommend installing into the same location as some other package manager does, this technique can be useful for debugging purposes; just remember to sudo make uninstall before installing via the owning package manager.

Upgrading to a new version of OSX on the same computer

When you upgrade OSX, you'll generally need to reinstall GNU Radio (and, all of its dependencies). If you are using MacPorts, you can follow their migration guide to do the reinstallation. You can always just remove all of the old installed files and/or reinstall over them.

Typical Errors and Warnings

Library not found

If you are compiling an out of tree module from source, some of them do not set the INSTALL_NAME by default. Without a correct set INSTALL_NAME, the library's self-id will be incorrect and the SWIG library will fail to be able to find the module's primary library. The actual runtime error will look like

ImportError: dlopen(/opt/local/lib/python2.7/site-packages/air_modes/_air_modes_swig.so, 2): Library not loaded: libair_modes.0.dylib
  Referenced from: /opt/local/lib/python2.7/site-packages/air_modes/_air_modes_swig.so
  Reason: image not found

Running "otool -L" on the libraries returns just the dependent library name without path, e.g.,

% otool -L  /opt/local/lib/python2.7/site-packages/air_modes/_air_modes_swig.so
/opt/local/lib/python2.7/site-packages/air_modes/_air_modes_swig.so:
        /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
        libair_modes.0.dylib (compatibility version 0.0.0, current version 0.0.0)
[snip]
% otool -L /opt/local/lib/libair_modes.dylib 
/opt/local/lib/libair_modes.dylib:
        libair_modes.0.dylib (compatibility version 0.0.0, current version 0.0.0)
[snip]

This issue has been fixed within GNU Radio and is in modtool, but has not been propagated to many projects. The simple solution is to paste the following chunk of code into the module's top-level CMakeLists.txt file (just after GR_LIBRARY_DIR is defined):

########################################################################
# On Apple only, set install name and use rpath correctly, if not already set
########################################################################
if(APPLE)
    if(NOT CMAKE_INSTALL_NAME_DIR)
        set(CMAKE_INSTALL_NAME_DIR
            ${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE
            PATH "Library Install Name Destination Directory" FORCE)
    endif(NOT CMAKE_INSTALL_NAME_DIR)
    if(NOT CMAKE_INSTALL_RPATH)
        set(CMAKE_INSTALL_RPATH
            ${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE
            PATH "Library Install RPath" FORCE)
    endif(NOT CMAKE_INSTALL_RPATH)
    if(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
        set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE
            BOOL "Do Build Using Library Install RPath" FORCE)
    endif(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
endif(APPLE)

Warnings: GTK

When executing a GNU Radio GUI, including gnuradio-companion, GTK will produce the following warnings on OSX 10.8; they can safely be ignored:

** (process:#####): WARNING **: Trying to register gtype 'GMountMountFlags' as enum when in fact it is of type 'GFlags'
** (process:#####): WARNING **: Trying to register gtype 'GDriveStartFlags' as enum when in fact it is of type 'GFlags'
** (process:#####): WARNING **: Trying to register gtype 'GSocketMsgFlags' as enum when in fact it is of type 'GFlags'

Error: Unusable DISPLAY

When executing a GNU Radio GUI, including gnuradio-companion, from a terminal window (e.g., Terminal.app, iTerm2.app, X11.app) when not the primary user or when the DISPLAY environment variable is not correctly set, one typically sees the following, regardless of OSX version:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display warnings.warn(str(e), _gtk.Warning)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnuradio/grc/gui/Actions.py:32: GtkWarning: gdk_keymap_get_for_display: assertion 'GDK_IS_DISPLAY (display)' failed

followed by a host of related failed assertions and errors.

If you are using Terminal.app, you'll need to switch to another terminal application such as XQuartz/X11.app or iTerm2.app.

If you are already using an application that correctly sets the DISPLAY environment variable, then you'll want to make sure you're logged in as the primary user (e.g., not as "su" to another user). If all else fails, try quitting and restarting the application. Try rebooting your computer. When all else fails, contact Michael.

Fatal error: 'unistd.h' file not found

If your install fails and you notice a line in the reported log file that says something like "Fatal error: 'unistd.h' file not found", it's likely due to the path to the active developer tools not correctly setup. To fix, simply execute the following command:

xcode-select --install

A confirmation dialog box will pop-up and the tools will be installed. From here, re-kickstart the gnuradio installation and you should be golden.