ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Using Catkin, what is the proper way to link against third party libraries?

asked 2013-07-08 04:25:03 -0500

Raptor gravatar image

updated 2014-01-28 17:17:10 -0500

ngrennan gravatar image

Hi ROS Community,

I am currently getting a "undefined reference" error when my ROS node is linking.

Here is my setup:

I have a ROS node that calls a library that I made, that is NOT built with ROS or inside the catkin build system.

My library that I built uses a third party system library that you can "apt-get install". For reference this is the " XML-RPC for C and C++" library found here

The problem:

The library that I made builds fine. Both a ".a" and ".so" file. So it is able to find the xmlrpc system library just fine.

When I try to build my ROS node that instantiates my library, everything builds fine, but when it gets to the linking step, it comes up with a bunch of "undefined references" to the xmlrpc library. So I know it knows the location of my library, because the build would fail, not just the linking part.


In my CMakeLists.txt, I included all the xmlrpc libraries under the "target_link_libraries()" macro and it can find these libraries as it does not complain that it can't find one of them. Here is what it looks like:

## Specify libraries to link a library or executable target against
target_link_libraries(my_ros_executables name_node

Is there another way that you need to tell Catkin about a secondary library or a library that is called by a library that you instantiate in your ROS node, besides the target_link_libraries?

I also built my application with another build system and everything compiled and linked fine, so it has to be something with catkin.


I just wanted to add that I also had "link_directories()" pointing to my library. The xmlrpc library shows up in /usr/lib and /usr/include/xmlrpc-c

What specific xmlrpc library does ROS use? I know there are a few such as:


XML-RPC for C and C++:

Here are the errors I am getting:

Linking CXX executable..../../my_ROS_node undefined reference to `xmlrpc_c::value_int::value_int(xmlrpc_c::value)' undefined reference to `xmlrpc_c::clientXmlTransport_curl::constrOpt::~constrOpt()' undefined reference to `xmlrpc_c::paramList::paramList(unsigned int)' undefined reference to `vtable for xmlrpc_c::rpcPtr' undefined reference to `xmlrpc_c::value::~value()' undefined reference to `xmlrpc_c::rpcPtr::operator->() const' undefined reference to `xmlrpc_c::clientTransactionPtr::~clientTransactionPtr()' undefined reference to `xmlrpc_c::value::~value()' undefined reference to `xmlrpc_c::value_string::operator std::basic_string<char, std::char_traits<char>, std::allocator<char> >() const' undefined reference to `xmlrpc_c::value_int::operator int() const' undefined reference to `xmlrpc_c::clientXmlTransport_curl::constrOpt::constrOpt()' undefined reference to `xmlrpc_c::paramList::add(xmlrpc_c::value)' undefined reference to `xmlrpc_c::clientXmlTransport_curl::constrOpt::timeout(unsigned int const&)' undefined reference to `xmlrpc_c::value_int::value_int(int)' undefined reference to ...
edit retag flag offensive close merge delete



Your assumption isn't fully correct: If the build succeeds and the link fails this means only the it knows the includes/headers of your library correctly. The link directory might still be wrong/missing. You should get a specific error when linking my_library then.

dornhege gravatar image dornhege  ( 2013-07-08 04:50:10 -0500 )edit

Thank you for your help. See update.

Raptor gravatar image Raptor  ( 2013-07-08 05:33:43 -0500 )edit

It looks like ROS uses the xmlrpc++ library, which is different then the XML-RPC for C and C++ library. The links are found under updates above. ROS calls the node xmlrpcpp:

Raptor gravatar image Raptor  ( 2013-07-08 05:53:22 -0500 )edit

@Raptor just fyi, you might want to avoid using link_directories? I found cmakedoc says that "the command is rarely necessary".

130s gravatar image 130s  ( 2013-07-08 08:45:53 -0500 )edit

How else would you link against non-ROS and non-system libraries that are not in your path?

Raptor gravatar image Raptor  ( 2013-07-08 09:38:45 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2013-07-08 09:42:15 -0500

Raptor gravatar image

I have seemed to fix the issue by rearranging the libraries in my CMAkeLists.txt file. I have changed the target_link_libraries() so the xmlrpc libraries are below my_library.

edit flag offensive delete link more

answered 2013-07-08 04:48:05 -0500

dornhege gravatar image

First, in general the way to link against third party libraries in catkin would be: The cmake way, i.e. don't do anything special.

With respect to your specific problem: You did not list the errors you get, so I can only guess that it is specific to xmlrpc. AFAIK ROS also uses xmlrpc, so if you depend on roscpp, you might not need to do anything or link it the same way. However, if there is some difference in the way that you and ROS link the library (or especially the version) you might have a larger problem.

For something more specific, you'd need to provide more details, especially what code you use and the linker errors.

edit flag offensive delete link more

Question Tools


Asked: 2013-07-08 04:25:03 -0500

Seen: 1,937 times

Last updated: Jul 08 '13