Installing ROS Melodic (Bare Bones) on MacOS Mojave

UPDATE: I cross-posted these instructions (edited for conciseness) on ROS.org.

Getting ROS to compile on MacOS (OS X) is an experience guaranteed to test your patience creativity in fixing build and runtime errors. After all, ROS does not officially support MacOS and its install guide is broken and outdated. With a few days of tinkering, I managed to build ROS Melodic and want to share the information. Here is my setup:

  • MacOS Mojave (v10.14.6) running on Macbook Pro
  • native Python 2.7.10 interpreter bundled with Mojave
    • (Homebrew Python 2.7.13 + pyenv also works)
  • XCode 11.2.1$ sudo apt-get install libcwiid1 libcwiid-dev libspnav-dev # cwiid.h and spnav.hMacOS Mojave (v10.14.6) running on Macbook Pro
  • native Python 2.7.10 interpreter bundled with Mojave
    • (Homebrew Python 2.7.13 + pyenv also works)
  • XCode 11.2.1

To be clear, I only built the Bare Bones (ROS-Comm) packages and not the more comprehensive Desktop or Desktop-Full packages. That’s because I currently need only the basic ROS components for tele-operating the robot and viewing the robot behavior on Gazebo on the Macbook. My robot’s Navigation stack is running on a separate Ubuntu host computer (Intel NUC Skull Canyon). I may build rviz or other packages on the Mac in future if needed.

For consistency, I followed the format of the OS X Installation guide .

1. Setup

1.1 Homebrew

First, go to http://brew.sh to install Homebrew and install some additional software:

Update Homebrew and install some additional software:

$ brew update
$ brew install cmake
$ brew install poco  # for class_loader pkg
$ brew install gpgme  # for rosbag_storage pkg

Add our ROS dependencies tap and the Homebrew science tap so you can get some non-standard formulae. (Only the first command is needed for Bare Bones. You may skip the others.)

$ brew tap ros/deps
$ brew tap osrf/simulation   # Gazebo, sdformat, and ogre 
$ brew tap homebrew/core # VTK5 
$ brew tap homebrew/science  # others 

Note: if you are upgrading from previous ROS distro try this before installing:

$ brew untap ros/DISTRO

In general it is not recommended to try and install multiple ROS versions at the same time on OS X due to conflicting system dependencies.

1.2 Setup Environment

You will need to tell Python about modules installed by Homebrew. The recommended way of doing this are the following commands:

$ mkdir -p ~/Library/Python/2.7/lib/python/site-packages 
$ echo "$(brew --prefix)/lib/python2.7/site-packages" >> ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth

1.3 Additional Tools

Finally, we need to install a few ROS python tools using ‘pip’.

NOTES:

  1. The following commands use the native Python 2.7 interpreter bundled with Mojave. If you decide to use Homebrew Python, you may encounter runtime issues. I’ve documented some workarounds in the Troubleshooting section below.
  2. I did not install the sphinx module because it requires fixing too many dependencies. It is not needed for Bare Bones.
$ sudo -H python -m pip install -U pip
$ sudo -H pip install -U wstool rosdep rosinstall rosinstall_generator rospkg catkin-pkg

Some required Python modules may not be pre-installed, so install them.

$ sudo -H pip install -U defusedxml empy pycryptodome

In order to use rosdep, we need to initialize it:

$ sudo -H rosdep init
$ rosdep update

2. Installation

Start by building the core ROS packages.

2.1 Create a catkin Workspace

In order to build the core packages, you will need a catkin workspace. Create one now:

$ mkdir ~/ros_catkin_ws
$ cd ~/ros_catkin_ws

Next we will want to fetch the core packages so we can build them. We will use wstool for this. Select the wstool command for the particular variant you want to install:

NOTE: I included all 3 variants for future reference. Presently, only the Ros-Comm (Bare Bones) variant is working.

Desktop-Full Install: ROS, rqtrviz, robot-generic libraries, 2D/3D simulators, navigation and 2D/3D perception

$ rosinstall_generator desktop_full --rosdistro melodic --deps --wet-only --tar > melodic-desktop-full-wet.rosinstall
$ wstool init -j8 src melodic-desktop-full-wet.rosinstall

Desktop Install (recommended): ROS, rqtrviz, and robot-generic libraries

$ rosinstall_generator desktop --rosdistro melodic --deps --wet-only --tar > melodic-desktop-wet.rosinstall
$ wstool init -j8 src melodic-desktop-wet.rosinstall

ROS-Comm: (Bare Bones) ROS package, build, and communication libraries. No GUI tools.

$ rosinstall_generator ros_comm --rosdistro melodic --deps --wet-only --tar > melodic-ros_comm-wet.rosinstall 
$ wstool init -j8 src melodic-ros_comm-wet.rosinstall 

This will add all of the catkin or wet packages in the given variant and then fetch the sources into the ~/ros_catkin_ws/src directory. The command will take a few minutes to download all of the core ROS packages into the src folder. The -j8 option downloads 8 packages in parallel.

If wstool init fails or is interrupted, you can resume the download by running:

$ wstool update -j 4 -t src

2.1.2 Modify some CMake config files

Now you will modify four CMake configuration files to avoid some compile and linker issues on MacOS.

  • Edit the files src/ros_comm/rosbag/CMakeLists.txt and src/ros_comm/rosbag_storage/CMakeLists.txt  by adding the lines below. Where you put it doesn’t really matter.. you can just insert them after the project(“package_name”) line at the top of the file.
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(APPLE)
  # Workaround to find missing libraries
  include_directories("/usr/local/opt/openssl/include")
  link_directories("/usr/local/opt/openssl/lib")
  link_directories("/usr/local/lib")  # GPGME library
endif()
  • Edit the file src/ros_comm/message_filters/CMakeLists.txt by removing the Boost.Signals package dependency. Look for the line:
find_package(Boost REQUIRED COMPONENTS signals thread)

and change it to:

find_package(Boost REQUIRED COMPONENTS thread)
  • Edit the file src/ros_comm/roscpp/CMakeLists.txt by removing the Boost.Signals package dependency.
find_package(Boost REQUIRED COMPONENTS chrono filesystem signals system)

and change it to:

find_package(Boost REQUIRED COMPONENTS chrono filesystem system) 

2.1.3 Resolving Dependencies

Before you can build your catkin workspace you need to make sure that you have all the required dependencies. We use the rosdep tool for this:

$ rosdep install --from-paths src --ignore-src --rosdistro melodic -y  --skip-keys google-mock

This will look at all of the packages in the src directory and find all of the dependencies they have. Then it will recursively install the dependencies.

The –from-paths option indicates we want to install the dependencies for an entire directory of packages, in this case src. The –ignore-src option indicates to rosdep that it shouldn’t try to install any ROS packages in the src folder from the package manager, we don’t need it to since we are building them ourselves. The –rosdistro option is required because we don’t have a ROS environment setup yet, so we have to indicate to rosdep what version of ROS we are building for. The -y option indicates to rosdep that we don’t want to be bothered by too many prompts from the package manager. The –skip-keys option gets rid of unwanted errors.

After a while (and maybe some prompts for your password) rosdep will finish installing system dependencies and you can continue.

NOTES:

  • Ignore the “Python 2.7 will reach the end of its life on January 1st, 2020.” warnings.
  • I ignored the following errors. You may encounter issues when running roslisp or rosbag, but I don’t use them (yet).
ERROR: the following packages/stacks could not have their rosdep keys resolved to system dependencies:  

roslisp: No definition of [python3-mock] for OS [osx]  
rosbag: No definition of [python-gnupg] for OS [osx]  
rosbag_storage: No definition of [libgpgme-dev] for OS [osx] 

2.1.4 Building the catkin Workspace

Once it has completed downloading the packages and resolving the dependencies you are ready to build the catkin packages. We will use the catkin_make_isolated command because there are both catkin and plain cmake packages in the base install, when developing on your catkin only workspaces you should use catkin/commands/catkin_make.

Invoke catkin_make_isolated:

$ ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release -DCMAKE_MACOSX_RPATH=ON -DCMAKE_INSTALL_RPATH=$HOME/ros_catkin_ws/install_isolated/lib

NOTE: The -DCMAKE_MACOSX_RPATH and -DCMAKE_INSTALL_RPATH flags are mandatory. They are needed by roscore (and other programs) to find the *.dylib libraries at runtime.

Now the packages should have been installed to ~/ros_catkin_ws/install_isolated or to wherever you specified with the –install-space argument. If you look in that directory you will see that a setup.bash file has been generated. To use the programs you built and installed, simply source the setup.bash file.

$ source ~/ros_catkin_ws/install_isolated/setup.bash

3. Try it out

  • Open a terminal console and run the ROS master:
$ source ~/ros_catkin_ws/install_isolated/setup.bash
$ roscore

You should see something like:

  • Open another terminal console and run another ROS node
$ source ~/ros_catkin_ws/install_isolated/setup.bash
$ rostopic info rosout

You should see something like:

4. Troubleshooting

In this section feel free to compile any tips or workarounds found for installing Melodic on OS X.

4.1 ‘No definition of [google-mock] for OS [osx]’ error during rosdep install

Add –skip-keys google-mock to rosdep install

4.2 empy fails

sudo -H pip install empy

4.2 ‘ImportError: No module named Crypto’

sudo -H pip install pycryptodome

4.3 ‘dyld: Library not loaded: libroscpp.dylib’ (or some other *.dylib file)

Run catkin_make_isolated with the CMAKE_MACOSX_RPATH and CMAKE_INSTALL_RPATH flags.

$ cd ~/ros_catkin_ws
$ ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release -DCMAKE_MACOSX_RPATH=ON -DCMAKE_INSTALL_RPATH=$HOME/ros_catkin_ws/install_isolated/lib

Leave a Reply

Your email address will not be published. Required fields are marked *