Ask Your Question
1

Linker goes bananas on Ubuntu 16.04 + ROS Kinetic + gcc 4.8

asked 2019-08-14 01:39:34 -0500

updated 2019-08-14 20:43:06 -0500

So, due to some peculiarities of my project I am in need of compiling everything with compiler suite version 4.8 instead of the default compiler version that comes with Ubuntu 16.04 ( 5.4 ). I used update-alternatives to set the compiler version (gcc, g++ etc...) to 4.8. But when I execute catkin_make, the linker starts complaining about not being able to find symbols like ros::NodeHandle, ros::init, etc...

Everything compiles and links just fine if I use the default compiler version (but I really need to compile with version 4.8).

To make sure that this is not due to the peculiarities of my project and development environment I have installed a fresh Ubuntu 16.04 + ROS Kinetic on a virtual machine, created a workspace containing the roscpp_tutorials and made sure that the following command works out of the box:

catkin_make -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -j1

Which compiles everthing and works and its all smiles and sunshine.

Then I install the compiler version 4.8 as follows:

sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 100
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 100
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100
sudo update-alternatives --set c++ /usr/bin/g++

I make sure to remove the directories build and devel from my catkin workspace:

secret_agent@CIA:~/top_secret/catkin_ws$ rm -rf build devel

And compile again:

secret_agent@CIA:~/top_secret/catkin_ws$ catkin_make -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -j1
Base path: /home/secret_agent/top_secret/catkin_ws
Source space: /home/secret_agent/top_secret/catkin_ws/src
Build space: /home/secret_agent/top_secret/catkin_ws/build
Devel space: /home/secret_agent/top_secret/catkin_ws/devel
Install space: /home/secret_agent/top_secret/catkin_ws/install
####
#### Running command: "cmake /home/secret_agent/top_secret/catkin_ws/src -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCATKIN_DEVEL_PREFIX=/home/secret_agent/top_secret/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/secret_agent/top_secret/catkin_ws/install -G Unix Makefiles" in "/home/secret_agent/top_secret/catkin_ws/build"
####
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/secret_agent/top_secret/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/secret_agent/top_secret/catkin_ws/devel;/opt/ros/kinetic
-- This workspace overlays: /home/secret_agent/top_secret/catkin_ws/devel;/opt/ros/kinetic
-- Found PythonInterp: /usr/bin/python (found version "2.7.12") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/secret_agent/top_secret/catkin_ws ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-08-15 01:34:32 -0500

updated 2019-08-15 01:36:16 -0500

So digging a little deeper, I found out that this might be due to ABI incompatibility between gcc-4.8 and gcc-5.

If the linker is complaining that it can not find a reference to ros::init, is because it can really not find it. Looking at the library /opt/ros/kinetic/lib/libroscpp.so we can see the references to ros::init are actually there:

secret_agent@CIA:~/top_secret/catkin_ws/build/roscpp_tutorials$ readelf -Ws /opt/ros/kinetic/lib/libroscpp.so | grep ros4init
  1968: 0000000000130950   566 FUNC    GLOBAL DEFAULT   12 _ZN3ros4initERKSt6vectorISt4pairINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_ESaIS8_EERKS7_j
  2303: 0000000000130170  2010 FUNC    GLOBAL DEFAULT   12 _ZN3ros4initERiPPcRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj
  2448: 000000000012da80   403 FUNC    GLOBAL DEFAULT   12 _ZN3ros4initERKSt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES6_St4lessIS6_ESaISt4pairIKS6_S6_EEERSA_j

Lets look at the object file that we are trying to link:

secret_agent@CIA:~/top_secret/catkin_ws/build/roscpp_tutorials$ nm CMakeFiles/parameters.dir/parameters/parameters.cpp.o | grep ros4init
             U _ZN3ros4initERiPPcRKSsj

Aha!!! The reference generated for ros::init by gcc-4.8 does not match the reference for ros::init in libroscpp! So, the linker is going bananas and rightfully so!!

This is because libroscpp has been compiled with Ubuntu 16.04 default compiler without old ABI backwards compatibility (if I am not mistaken this would be achieved by the flag -D_GLIBCXX_USE_CXX11_ABI=0.

Obviously, compiling the code with the default version (gcc-5) generates the correct references and the linker is happy.

So, I guess my only option would be to compile ROS from source code and pray that all system libraries are ABI compatible with gcc-4.8 which is not practical for my project.

Tough luck -_-

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2019-08-14 01:39:34 -0500

Seen: 31 times

Last updated: Aug 15