ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Undefined symbol ros::Publisher::~Publisher with Boost Python

asked 2015-03-14 00:23:44 -0500

Nathan Powel gravatar image

I have some code written in C++ that I want to wrap using Boost Python so that a colleague can use it in an RQT widget. The code is just a few functions in a library and the wrapper code compiles without errors. However, when I try to import the resulting Python module I get:

ImportError: catkin_ws/devel/lib/
undefined symbol: _ZN3ros9PublisherD1Ev

which de-mangles to ros::Publisher::~Publisher. I'm confused because none of the functions in the wrapped library (guidance_factory) make any ROS function calls, though they call static methods of a class (Guidance) which has ros::Publisher objects as member variables. The wrapped methods do this without instantiating the class (I didn't wrap the instantiator method of the factory, nor did I wrap the classes) or referencing the Publisher variables directly or indirectly.

I've followed the example at: ROS/Tutorials/Using a C++ class in Python with appropriate name conversions and the wrapper library shows up in catkin_ws/devel/lib/python2.7/dist-packages/wrapper-pkg/ as expected.

I've determined the following: (the python wrapper library) links to (the C++ library being wrapped) which links to (the parent class of those classes whose static methods are used) as well as all the child class libs. None of these libraries contain the ros::Publisher symbol (expected) or link to (slightly unexpected). This is apparently not usually a problem because these libraries have only every been run linked from executables/nodes that do link My CMakeLists.txt does includes

find_package(catkin REQUIRED COMPONENTS roscpp)



so I would expect roscpp to be linked.

I'm using Indigo on Ubuntu 14.04. The wrapper code is currently in a different package from the library it's wrapping, but the wrapped library is being exported and the wrapper code compiles.

How can I either get the required linkage to work or else convince catkin that I don't need that symbol anyway? Thanks in advance.

edit retag flag offensive close merge delete


rqt also accepts plugins written directly in Python. That might be simpler and easier to maintain.

joq gravatar image joq  ( 2015-03-14 10:57:35 -0500 )edit

Yes, that's what I am trying to do. My colleague is trying to write an RQT plugin in Python, but he needs to make function calls to my C++ library (guidance_factory), so I'm trying to wrap my C++ library in Python using Boost Python. It compiles, it just won't load.

Nathan Powel gravatar image Nathan Powel  ( 2015-03-14 13:16:40 -0500 )edit

Make sure you don't call find_package(catkin REQUIRED COMPONENTS ....) more than once other wise the catkin_LIBRARIES variable will not contain what you think. You can also message(..) out the value of catkin_LIBRARIES to ensue it contains the entry.

William gravatar image William  ( 2015-03-14 18:14:02 -0500 )edit

Rqt also works with CPP plugins. Then you don't have to deal with bindings at all.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-03-14 20:34:06 -0500 )edit

@Dirk That is a fallback option. My colleague doesn't know C++ though, so if we go that route, I'm the one who has to write it. I see there is now tutorial for writing C++ RQT plugins, which wasn't there when I looked before, so that makes it more possible.

Nathan Powel gravatar image Nathan Powel  ( 2015-03-14 21:43:13 -0500 )edit

@William I added message(catkin_LIBRARIES) in my build file and was listed. But if I ldd (my Python module) isn't listed. I don't have two calls to find_package(catkin REQUIRED ...).

Nathan Powel gravatar image Nathan Powel  ( 2015-03-14 21:45:38 -0500 )edit

Does your package that contains the lib also have roscpp as dependency? Also your lib package should typically occur in find_package(catkin REQUIRED COMPONENTS roscpp), too? Moreover it should export the lib and its deps in catkin_package of CMakelists.txt

Wolf gravatar image Wolf  ( 2015-03-16 08:36:18 -0500 )edit

I guess that would make the guidance_factory in target_link_libraries(guidance_ext guidance_factory ${catkin_LIBRARIES} ${Boost_LIBRARIES} ) obsolete??

Wolf gravatar image Wolf  ( 2015-03-16 08:37:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-17 13:20:18 -0500

Nathan Powel gravatar image

updated 2015-03-17 13:20:33 -0500

I ended up fixing this by making sure to link to ${catkin_LIBRARIES}. I thought it already had been, but a second look revealed otherwise. Why this never bit me before, I'm not sure.

So to sum up: the problem was a missing link on a library (Guidance) that the library I was wrapping (guidance_factory) was linking to.

Thanks all, for your responses.

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


Asked: 2015-03-14 00:23:44 -0500

Seen: 710 times

Last updated: Mar 17 '15