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

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

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

Raptor gravatar image

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

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 http://xmlrpc-c.sourceforge.net/

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.

Conclusion:

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
xmlrpc++
xmlrpc
xmlrpc_abyss
xmlrpc_client++
xmlrpc_client
xmlrpc_packetsocket
xmlrpc_server
xmlrpc_server++
xmlrpc_server_abyss
xmlrpc_server_abyss++
xmlrpc_server_cgi
xmlrpc_server_cgi++
xmlrpc_server_pstream++
xmlrpc_util
xmlrpc_xmlparse
xmlrpc_xmltok
my_library
${catkin_LIBRARIES}
)

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.

Update

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:

XmlRpc++: http://sourceforge.net/projects/xmlrpcpp/

XML-RPC for C and C++: http://xmlrpc-c.sourceforge.net/

Here are the errors I am getting:

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

Comments

1

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 -0600 )edit

Thank you for your help. See update.

Raptor gravatar image Raptor  ( 2013-07-08 05:33:43 -0600 )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: http://ros.org/wiki/xmlrpcpp

Raptor gravatar image Raptor  ( 2013-07-08 05:53:22 -0600 )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 -0600 )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 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

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

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
1

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

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

Stats

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

Seen: 2,017 times

Last updated: Jul 08 '13