ros-visualization / rviz

ROS 3D Robot Visualizer
BSD 3-Clause "New" or "Revised" License
847 stars 463 forks source link

Bindings not building correctly for Python 3 on Ubuntu Xenial #1361

Closed mikepurvis closed 5 years ago

mikepurvis commented 5 years ago

When building rviz from source on Xenial with -DPYTHON_EXECUTABLE=python3 I end up with the following in my installspace:

$ find lib -name *rviz*
lib/librviz.so
lib/rviz
lib/rviz/rviz
lib/pkgconfig/rviz.pc
lib/librviz_default_plugin.so
lib/python3/dist-packages/rviz-1.12.16.egg-info
lib/python3/dist-packages/rviz
lib/python3/dist-packages/rviz/librviz_sip.so

Seems reasonable enough, however, the Python bindings are linked against the wrong libpython:

$ ldd lib/python3/dist-packages/rviz/librviz_sip.so | grep python
        libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f766c63b000)

Other bindings in this same workspace are doing the right thing:

$ ldd lib/python3/dist-packages/tf2_py/_tf2.so | grep python
        libpython3.5m.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 (0x00007ff82d5f6000)
$ ldd lib/python3/dist-packages/roslz4/_roslz4.so | grep python
        libpython3.5m.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 (0x00007f184e4f2000)

So it's not clear to me if this is an issue with the SIP generator (the other bindings are non-SIP) or a problem with rviz's use of it, but for now I'm ticketing the issue here.

mikepurvis commented 5 years ago

Building the bindings lib with VERBOSE=1 yields a bunch of compile lines like:

g++ -c -std=c++11 -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Wall -W -D_REENTRANT -DNDEBUG -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_GUI_LIB -I. -I/home/administrator/rviz_ws/src/rviz/src -I/home/administrator/rviz_ws/install/include -I/home/administrator/rviz_ws/install/share/xmlrpcpp/cmake/../../../include/xmlrpcpp -I/usr/include -I/usr/include/eigen3 -I/usr/include/python3.5m -I/usr/share/qt5/mkspecs/linux-g++ -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtPrintSupport -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/X11R6/include -o siplibrviz_siprviz.o siplibrviz_siprviz.cpp

And a link line like:

g++ -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-rpath,"/home/administrator/rviz_ws/devel/rviz/lib" -shared -Wl,--version-script="/home/administrator/rviz_ws/devel/rviz/lib/python3/dist-packages/rviz/librviz_sip".exp -o "/home/administrator/rviz_ws/devel/rviz/lib/python3/dist-packages/rviz/librviz_sip".so siplibrviz_sipcmodule.o siplibrviz_siprvizYamlConfigReader.o siplibrviz_siprvizYamlConfigWriter.o siplibrviz_siprvizConfigMapIterator.o siplibrviz_siprvizConfig.o siplibrviz_siprvizOgreLogging.o siplibrviz_siprvizToolManager.o siplibrviz_siprvizTool.o siplibrviz_siprvizViewManager.o siplibrviz_siprvizViewController.o siplibrviz_siprvizPanelDockWidget.o siplibrviz_siprvizBoolProperty.o siplibrviz_siprvizDisplayGroup.o siplibrviz_siprvizDisplay.o siplibrviz_siprvizProperty.o siplibrviz_siprvizVisualizationManager.o siplibrviz_siprvizVisualizationFrame.o siplibrviz_siprviz.o -L/home/administrator/rviz_ws/devel/rviz/lib -L/usr/lib/x86_64-linux-gnu -L/usr/X11R6/lib -lrviz -lQt5Core -lQt5Gui -lXext -lX11 -lm -lpthread

Looks like the problem is not coming in via sip but is rather because librviz.so itself is being linked with -lpython2.7:

$ ldd lib/librviz.so | grep python
        libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f3fa40c3000)
mikepurvis commented 5 years ago

Oh blah, this might be particular to my setup. Going to close it for now and investigate further.

mikepurvis commented 5 years ago

Just to circle back here— the issue was trying to build a hybrid workspace with rviz and its dependency tree against Python 3 while portions of the system underlay were built for Python 2 or dual-built. The libpython2.7.so linkage is actually coming in via roslib and rospack, because librospack links against Python 2:

https://github.com/ros/rospack/blob/lunar-devel/src/rospack.cpp#L28