Skip to content

Instantly share code, notes, and snippets.

@johnboiles
Last active June 8, 2024 02:33
Show Gist options
  • Save johnboiles/c8139c8869306334550b to your computer and use it in GitHub Desktop.
Save johnboiles/c8139c8869306334550b to your computer and use it in GitHub Desktop.
How to build GNURadio modules from source on OSX 10.9 with GNURadio installed via MacPorts

Building GNURadio Modules on OSX with MacPorts

I'm on OSX 10.9.4 and recently picked up an RTL2832u dongle. After trying to get GNURadio to build on Homebrew, I gave up and installed MacPorts (via Homebrew using Cask). Since MacPorts and Homebrew don't always play nicely, I silo'd my MacPorts PATH settings using this technique. With this method, you prefix any commands that you want to run in a MacPorts-friendly environment with a script that sets up your PATH. This keeps MacPorts from intruding when I don't want to use the things installed by MacPorts (which is most of the time). That script is also included in this Gist.

Not sure if it's unique to installs that use both MacPorts and Homebrew, but I ran into several issues:

  • PMT would raise linker errors that looked like this Undefined symbols for architecture x86_64: pmt::dict_has_key(. I fixed this by modernizing the project I was working on (gr-ais) by replacing all the CMakeLists.txt files with ones from a modern GNURadio module and re-adding the project-specific file lists. This was likely due to something crufty in gr-ais, but including here just in case.
  • **CMake would detect the OSX libpython2.7.dylib (for CMake dependency PythonLibs) instead of the MacPorts libpython2.7.dylib.** To fix this I set the evironment variable CMAKE_PREFIX_PATH="/opt/local"(in my case I addedexport CMAKE_PREFIX_PATH="$MACPORTS_PREFIX"to myuse_macports.sh` script)
  • CMake would detect the OSX Python interpreter (for CMake dependency PythonInterp) instead of the MacPorts Python interpreter. To fix this I symlinked /opt/local/bin/Python2.7 to /opt/local/bin/python (using sudo ln -s /opt/local/bin/Python2.7 /opt/local/bin/python). This helped CMake choose the right one. Note that /opt/local/bin/Python2.7 is itself a symlink.
  • The module would try to install to /usr/local instead of /opt/local. This I fixed by setting -DCMAKE_INSTALL_PREFIX=/opt/local when running CMake. For example mkdir build; cd build; use_macports.sh cmake -DCMAKE_INSTALL_PREFIX=/opt/local ../
  • Python modules would get installed to /opt/local/lib/python2.7/site-packages, while the correct MacPorts place to install modules is /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. I fixed this by symlinking the former location to the latter (ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /opt/local/lib/python2.7) (See the (MacPorts wiki)[https://trac.macports.org/wiki/Python] for best practices on locations for Python files)
  • The module's Python app couldn't load the modules Python package. Not sure why this is, but even though the app (ais_rx, in my case) was using /opt/local/bin/Python2.7 (which is symlinked to /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python), /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages wasn't in sys.path. I fixed this by adding that directory to the PYTHONPATH. (in my case I added export PYTHONPATH="$MACPORTS_PREFIX/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH" to my use_macports.sh script)

Now I can build and install GNURadio modules from source by running:

mkdir build && cd build && use_macports cmake -DCMAKE_INSTALL_PREFIX=/opt/local ../ && make && sudo make install

Hopefully this helps someone. If anyone can enlighten me on better ways to do the same thing, I'd love to learn.

#!/bin/sh
## Wrap Macports command (any executables installed by Macports).
## Originally from http://www.topbug.net/blog/2013/10/23/use-both-homebrew-and-macports-on-your-os-x/
if [ "$#" -le 0 ]; then
echo "Usage: $0 command [arg1, arg2, ...]" >&2
exit 1
fi
if [[ -z $MACPORTS_PREFIX ]]; then
MACPORTS_PREFIX='/opt/local'
fi
export PATH="$MACPORTS_PREFIX/bin:$MACPORTS_PREFIX/sbin:$PATH"
export CPATH="$MACPORTS_PREFIX/include:$CPATH"
export MANPATH="$MACPORTS_PREFIX/share/man:$MANPATH"
export CMAKE_PREFIX_PATH="$MACPORTS_PREFIX"
export PYTHONPATH="$MACPORTS_PREFIX/lib/python2.7/site-packages/:$PYTHONPATH"
command=$1
shift
exec $command $*
@EvanKrall
Copy link

One little thing that bothered me about the use_macports.sh script is the last 3 lines. I replaced these with

exec "$@"

which should handle arguments with spaces better.

@EvanKrall
Copy link

When building gr-osmosdr, I had to use_macports port install py-cheetah and then make sure /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages was in my PYTHONPATH when running make.

@EvanKrall
Copy link

Oh, I see you addressed this in one of the bullet points.

@chand01
Copy link

chand01 commented Oct 21, 2015

i am building an out of tree module in gnuradio on mac but sudo ldconfig command don't works. Can anyone help me with this?

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