Using Catkin, what is the proper way to link against third party libraries?
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 ...
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.
Thank you for your help. See update.
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 just fyi, you might want to avoid using
link_directories
? I foundcmake
doc says that "the command is rarely necessary".How else would you link against non-ROS and non-system libraries that are not in your path?
This should work: http://ros.org/doc/groovy/api/catkin/html/howto/system_library_dependencies.html