MacOS Sierra 配置 ROS Kinetic

MacOS Sierra 配置 ROS Kinetic

系统环境:MacOS Sierra 10.12.6 系统
安装软件:ROS Kinetic
相关参考:

FindBoost: Add Boost 1.65 dependencies
Boost 1.65.0 build failure on macOS 10.12
Installing ROS Kinetic on Mac OS X – El Capitan and macOS Sierra
ros-install-osx
Installation Instructions for Kinetic in OS X

 

【前言】在第一次尝试安装ROS Kinetic多次长达两天的时间后,我原本放弃了ROS Kinetic版本的安装,虽然我也不知道安装这个版本的意义是啥。但是亲身经历告诉我,这个版本真的是不要再作死的继续安装下去。官网也是低调说ROS Kinetic对MacOS的不支持。
然后我就试图在MacOS上安装ROS Indigo版本,结果安装到一半遇到了Qt Version = 4.x的迷之尴尬(Qt版本我已经更新到Qt 5.9.1),然后我就下狠心准备作死到位,重新第二次安装ROS Kinetic版本。结果最终第二天早上安装完成。

 

1. 安装homebrew和其依赖项

(1) 安装homebrew以及额外的cmake【如果已经安装过了homebrew和cmake,无需进行此步骤】

1- brew update
2- brew install cmake

(2) 安装ROS和homebrew部分依赖项

1- brew tap ros/deps
2- brew tap osrf/simulation   # Gazebo, sdformat, and ogre
3- brew tap homebrew/core # VTK5
4- brew tap homebrew/science  # others

 

2. ROS安装环境设置

告诉python那些来自homebrew已经安装好的模块和依赖项【如果~/Library/Python/2.7/lib/python/site-packages文件夹已经存在,无需进行mkdir指令】

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

 

3. 安装额外的所需工具包

(1) 使用pip指令安装以下相关工具包【如果没有安装过pip指令,可见第二步】

sudo -H pip install -U wstool rosdep rosinstall rosinstall_generator rospkg catkin-pkg Distribute sphinx

(2) 无pip指令安装以上相关工具包

1- brew install python  # brew Python comes with pip
2- sudo -H python -m pip install -U pip  # Update pip

(3) 初始化rosdep

1- sudo -H rosdep init
2- rosdep update

 

4. ROS核心包安装

(1) 构建catkin工作区并进入工作区

1- mkdir ~/ros_catkin_ws
2- cd ~/ros_catkin_ws

(2) 根据个人需求安装ROS核心包

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

1- rosinstall_generator desktop_full --rosdistro kinetic --deps --wet-only --tar > kinetic-desktop-full-wet.rosinstall
2- wstool init -j8 src kinetic-desktop-full-wet.rosinstall

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

1- rosinstall_generator desktop --rosdistro kinetic --deps --wet-only --tar > kinetic-desktop-wet.rosinstall
2- wstool init -j8 src kinetic-desktop-wet.rosinstall

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

1- rosinstall_generator ros_comm --rosdistro kinetic --deps --wet-only --tar > kinetic-ros_comm-wet.rosinstall
2- wstool init -j8 src kinetic-ros_comm-wet.rosinstall

如果长时间下载未完成的话,可以中断进程,然后启动以下指令继续完成

wstool update -j 8 -t src

(3) **【详细指令见6. 解决依赖】在你构建最终的catkin工作区之前,你需要检查是否所有依赖项已经安装完毕
【这步骤一直让我认为所有依赖项都已经安装完毕了,但是直到后面一大堆编译错误我才发现我是真的错了】

rosdep install --from-paths src --ignore-src --rosdistro indigo -y

 

5. 安装补丁

补丁的目的和作用目前不明,但是有总比没有好嘛。

# Grabbing these older meshes allows rviz to run with Ogre 1.7 rather than Ogre 1.8+.
# Some details here: https://github.com/ros-visualization/rviz/issues/782
1- cd src/rviz/ogre_media/models
 2- curl https://raw.githubusercontent.com/ros-visualization/rviz/hydro-devel/ogre_media/models/rviz_cone.mesh > rviz_cone.mesh
 3- curl https://raw.githubusercontent.com/ros-visualization/rviz/hydro-devel/ogre_media/models/rviz_cube.mesh > rviz_cube.mesh
 4- curl https://raw.githubusercontent.com/ros-visualization/rviz/hydro-devel/ogre_media/models/rviz_cylinder.mesh > rviz_cylinder.mesh
 5- curl https://raw.githubusercontent.com/ros-visualization/rviz/hydro-devel/ogre_media/models/rviz_sphere.mesh > rviz_sphere.mesh
6- cd -
# This patch originates from here: https://github.com/ros/catkin/pull/784
7- cd  src/catkin/cmake
  8- curl https://raw.githubusercontent.com/ros/catkin/8a47f4eceb4954beb4a5b38b50793d0bbe2c96cf/cmake/catkinConfig.cmake.in > catkinConfig.cmake.in
9- cd -

 

6.解决依赖

默认执行指令为

rosdep install --from-paths src --ignore-src --rosdistro kinetic -y --as-root pip:no --skip-keys=python-qt-bindings-qwt5

但是由于homebrew安装qt5是keg-only,rosdep会对qt5是否成功安装存在质疑,可能会出现以下内容报错

Failed to detect successful installation of [qt5]

如果出现以上错误,可以尝试以下指令为保周全

rosdep install --from-paths src --ignore-src --rosdistro kinetic -y --as-root pip:no --skip-keys "libqt5-core libqt5-gui libqt5-opengl libqt5-opengl-dev libqt5-widgets qt5-qmake qtbase5-dev  python-qt5-bindings python-qt5-bindings-gl python-qt5-bindings-webkit"

 

7. 构建最终的catkin工作区

下面将介绍两种安装方式,这两种安装方式的结果并没有很大区别。

个人比较建议第二种安装方式,不仅仅是因为这种安装途径成功了,主要是因为终端显示界面简单明了。

****鉴于很多部分错误需要brew安装依赖项来解决的,所以我建议以下两种方案均需要提前安装以下依赖项****

brew install boost boost-build boost-python cmake tinyxml gtest assimp ghull yaml-cpp libogg theora gazebo7

 

****鉴于【错误4】和【错误5】是程序代码错误导致的,所以我建议以下两种方案均需要提前修改对应的以下代码文件中的对应字段****

~/ros_catkin_ws/src/rospack/src/utils.cpp
【第二种方案路径为】~/kinetic_ros_desktop_full_ws/src/rospack/src/utils.cpp

#include <boost/tr1/unordered_set.hpp> –> #include <boost/unordered_set.hpp>

std::tr1::unordered_set –> boost::unordered_set

~/ros_catkin_ws/src/rospack/src/rospack.cpp
【第二种方案路径为】~/kinetic_ros_desktop_full_ws/src/rospack/src/rospack.cpp

std::tr1::unordered_set –> boost::unordered_set

std::tr1::unordered_map –> boost::unordered_map

~/ros_catkin_ws/src/rospack/include/rospack/rospack.h
【第二种方案路径为】~/kinetic_ros_desktop_full_ws/src/rospack/include/rospack/rospack.h

std::tr1::unordered_set –> boost::unordered_set

std::tr1::unordered_map –> boost::unordered_map

#include <boost/tr1/unordered_set.hpp> –> #include <boost/unordered_set.hpp>

#include <boost/tr1/unordered_map.hpp> –> #include <boost/unordered_map.hpp>

 

–》第一种安装方式:第一次安装的时候用的是官网提供的方式

./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release

之后就将进入漫长的共计228个项目编译报错等待过程。

 

–》第二种安装方式:第二次安装的时候是膜拜了github上一些部分安装成功的大神方案

(1) 工作区路径名变更为~/kinetic_ros_desktop_full_ws,安装路径为/opt/ros/kinetic,并未给该路径赋予权限

1- sudo mkdir -p /opt/ros/kinetic
2- sudo chown $USER /opt/ros/kinetic

(2) 配置编译选项

catkin config --install  --install-space /opt/ros/kinetic --cmake-args \
    -DCMAKE_FIND_FRAMEWORK=LAST \
    -DCATKIN_ENABLE_TESTING=1 \
    -DCMAKE_BUILD_TYPE=Release \
    -DPYTHON_LIBRARY=$(python -c "import sys; print sys.prefix")/lib/libpython2.7.dylib \
    -DPYTHON_INCLUDE_DIR=$(python -c "import sys; print sys.prefix")/include/python2.7  \
    -DPYTHON3_LIBRARY=$(python3 -c "import sys; print (sys.prefix)")/lib/libpython3.6.dylib \
    -DPYTHON3_INCLUDE_DIR=$(python3 -c "import sys; print (sys.prefix)")/include/python3.6m \
    -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -DQT_MAC_USE_COCOA" 
    -DBOOST_ROOT=/usr/local/Cellar/boost/1.65.0 
    -DBOOST_LIBRARYDIR=/usr/local/Cellar/boost/1.65.0/lib 
    -DBOOST_INCLUDEDIR=/usr/local/Cellar/boost/1.65.0/include/boost 
    -Wno-dev

其中红色部分是可加可不加。根据你是否存在相关boost报错来决定的。执行该指令之后执行如图所示,其中红框部分的文件夹需要自行在工作区内部创建

(3) 进行编译

catkin build --limit-status-rate 1

编译过程如图所示。编译是个相当非常漫长的过程。尤其编译opencv3的时候会等待很久。中间遇到很多的问题,如果遇到问题,提示不太明显,可以cd到~/kinetic_ros_desktop_full_ws/logs文件中相应的build目录。例如opencv3编译出错,则可以cd ~/kinetic_ros_desktop_full_ws/logs/opencv3,然后查看build.cmake(make).00*.log显示更多信息。

出现如下截图则表明ROS Kinect安装成功。【时间是我基于编译成功的基础上再次编译的结果。实际编译时间在一小时以上】

 

8. 相关警告以及错误解决方案

【警告】CMake Warning at /usr/share/cmake-3.5/Modules/FindBoost.cmake:740 (message):

Imported targets not available for Boost version 106500

boost1.65.0版本过高,而cmake3.9.1版本过低,所以根据github最新源中的FindBoost: Add Boost 1.65 dependencies更新cmake中的FindBoost.cmake。或者直接Download新的FindBoost.cmake并替换/usr/local/cmake/3.9.1/share/cmake/Modules/中的FindBoost.cmake

-    message(WARNING "Imported targets not available for Boost version ${Boost_VERSION}")
-    set(_Boost_IMPORTED_TARGETS FALSE)
+    if(NOT Boost_VERSION VERSION_LESS 106500)
+      set(_Boost_CHRONO_DEPENDENCIES system)
+      set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time)
+      set(_Boost_COROUTINE_DEPENDENCIES context system)
+      set(_Boost_FIBER_DEPENDENCIES context thread chrono system date_time)
+      set(_Boost_FILESYSTEM_DEPENDENCIES system)
+      set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+      set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
+      set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+      set(_Boost_MPI_DEPENDENCIES serialization)
+      set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+      set(_Boost_NUMPY_DEPENDENCIES python)
+      set(_Boost_RANDOM_DEPENDENCIES system)
+      set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+      set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+      set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+    endif()
+    if(NOT Boost_VERSION VERSION_LESS 106600)
+      message(WARNING "New Boost version may have incorrect or missing dependencies and imported targets")
+      set(_Boost_IMPORTED_TARGETS FALSE)
+    endif()

 

出现以下任何错误,我都建议删除build_isolated文件夹并重新进行编译

【错误1】Unable to find the requested Boost libraries.

brew install boost

最好不要找来boost源码包编译,编译后执行./b2安装之后你会发现,这个错误依然存在

在/etc/profile里面添加环境变量设置:

export BOOST_LIBRARYDIR=/usr/local/Cellar/boost/1.65.0/lib
export BOOST_INCLUDEDIR=/usr/local/Cellar/boost/1.65.0/include

然后source /etc/profile使其生效

【错误2】The imported target “Qt5::Core” references the file

“/usr/local/.//mkspecs/macx-clang”

如果没有安装过qt5,则先安装qt5

brew install qt5

安装过qt5的话则先删除已存在的链接,再重新链接(其中路径根据自己的电脑环境来定)

1- brew unlink qt
2- brew link --force qt5
3- echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.zshrc
4- sudo ln -s /usr/local/Cellar/qt/5.9.1/mkspecs /usr/local/mkspecs
5- sudo ln -s /usr/local/Cellar/qt/5.9.1/plugins /usr/local/plugins

【错误3】Could NOT find TinyXML (missing: TINYXML_LIBRARY TINYXML_INCLUDE_DIR)

brew install tinyxml

同样不要找来tinyxml源码,你会发现那些就是些头文件和库文件

【错误4】~/ros_catkin_ws/src/rospack/include/rospack/rospack.h:108:10:

fatal error:’boost/tr1/unordered_set.hpp’ file not found

将~/ros_catkin_ws/src/rospack/include/rospack中的rospack.h中第108行和第109行的

#include <boost/tri/unordered_set.hpp>
#include <boost/tri/unordered_map.hpp>

修改为

#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>

【错误5 与错误4问题一致】~/ros_catkin_ws/src/rospack/src/utils.cpp:31:10:

fatal error:’boost/tr1/unordered_set.hpp’ file not found

将~/ros_catkin_ws/src/rospack/src中的utils.cpp中第31行

#include <boost/tri/unordered_set.hpp>

修改为

#include <boost/unordered_set.hpp>

【错误6】CMake Error at test/CMakeLists.txt:4 (target_link_libraries):

Cannot specify link libraries for target “resource_retriever_utest” which is not built by this project.

brew install gtest

【错误7】Failed to process package ‘geometric_shapes’:

1- brew install assimp qhull
2- sudo pip install nose

【错误8】CMake Error at CMakeLists.txt:30 (if):if given arguments:

“VERSION_GREATER” “0.5”

Unknown arguments specified

brew install yaml-cpp

【错误9】CMake Error at /usr/local/Cellar/cmake/3.9.1/share/cmake/Modules/FindBoost.cmake:1903 (message):

Unable to find the requested Boost libraries.

Boost version: 1.65.0

Could not find the following Boost libraries:

boost_python

brew install boost-python

然后将/usr/local/Cellar/boost-python/1.65.0/lib下全部文件拷贝到/usr/local/Cellar/boost/1.65.0/lib中去

【错误10】CMake Error at /usr/local/Cellar/cmake/3.9.1/share/cmake/Modules/FindPkgConfig.cmake:412 (message):

A required package was not found

No package ‘theora’ found
No package ‘ogg’ found

brew install libogg theora

【错误11】CMake Error at /opt/ros/kinetic/share/gazebo_dev/cmake/gazebo_dev-extras.cmake:2 (find_package):

By not providing “Findgazebo.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “gazebo”, but
CMake did not find one.

Could not find a package configuration file provided by “gazebo” with any
of the following names:

gazeboConfig.cmake
gazebo-config.cmake

brew install gazebo7

【错误12】/usr/local/Cellar/boost/1.65.0/include/boost/thread/pthread/pthread_mutex_scoped_lock.hpp:33:26: error: expected member name or ‘;’ after declaration specifiers

void check() BOOST_NOEXCEPT

~~~~            ^

/usr/local/Cellar/boost/1.65.0/include/boost/thread/pthread/condition_variable.hpp:82:43: error: expected unqualified-id

check_for_interruption.check();

~~~~                                               ^

在出错的~/kinetic_ros_desktop_full_ws/src中对应的项目文件中的CMakeLists.txt文件中添加以下指令

add_definitions(
    # See boost 1.65 breakage https://github.com/Homebrew/homebrew-core/pull/17150
    -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0
)

2 Replies to “MacOS Sierra 配置 ROS Kinetic”

  1. 严格按照你的步骤,还是不行,在编译rviz的时候出错了,好遗憾。放弃了,还是安心用虚拟机。谢谢你的教程,少走了很多弯路。

发表评论