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

How to link to third party library ?

asked 2012-07-30 04:29:50 -0500

Erwan R. gravatar image

updated 2014-01-28 17:13:11 -0500

ngrennan gravatar image


I'm still working on the communication between ROS electric and Promethe Neural Network simulator and I'm trying to rosmake a node that includes Promethe C functions. I'm using the following CMakeLists.txt :

I can rosmake witjout error but I get :

[rosmake-0] Finished <<< promROS_connector [SKIP] No rule to make target None

And no executable in bin/ . I would know if my CMakeLists is correct and what I exactly have to use to compile with third party C compiled libraries. The ~/simulateur is in ROS_PACKAGE_PATH.

Thanks for reading and answering.

cmake_minimum_required(VERSION 2.4.6)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)


#set the default path for built executables to the "bin" directory
#set the default path for built libraries to the "lib" directory

#uncomment if you have defined messages
#uncomment if you have defined services

#common commands for building c++ executables and libraries

#****************** INCLUDES **************************





rosbuild_add_executable(prom2ROS src/prom_to_ROS.cpp)
target_link_libraries(prom2ROS ~/simulateur/lib/Linux/comm/libcomm_debug)


After using :

 target_link_libraries(prom2ROS libcomm_debug)

the error is :

   Linking CXX executable ../bin/prom2ROS
   /usr/bin/ld: cannot find -llibcomm_debug
   collect2: ld returned 1 exit status

Does I have to set the LD_LIBRARY_PATH to allow ld to find the libcomm_debug (it is now empty - libcomm_debug is a .a static library) ?

edit retag flag offensive close merge delete


Does target_link_libraries(prom2ROS -lcomm_debug) work? (libcomm_debug is already prebuild?)

dornhege gravatar image dornhege  ( 2012-07-30 04:34:20 -0500 )edit

Also, what is: promROS_connector? The ~/simulateur doesn't need to be in the package path as it is not a ROS package (right? otherwise you should like via export flags in the manifest)

dornhege gravatar image dornhege  ( 2012-07-30 04:35:40 -0500 )edit

@dornhege: remove the '-l' prefix, that should work. CMake expects library names in target_link_libraries, it is not a direct replacement for what you'd write in a linking statement for ld, as CMake performs dependency resolution on the listed libraries.

ipso gravatar image ipso  ( 2012-07-30 04:43:30 -0500 )edit

Yes, that's nicer.

dornhege gravatar image dornhege  ( 2012-07-30 05:24:00 -0500 )edit

target_link_libraries(prom2ROS libcomm_debug) is better in the sense that it throw an error - I'm editing the message for more details. Thanks for help.

Erwan R. gravatar image Erwan R.  ( 2012-07-30 05:26:07 -0500 )edit

@Erwan R.: see my edit, I forgot to remove the lib prefix.

ipso gravatar image ipso  ( 2012-07-30 05:39:49 -0500 )edit

Done, it works ! Many many thanks !

Erwan R. gravatar image Erwan R.  ( 2012-07-30 05:46:30 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-07-30 04:36:52 -0500

ipso gravatar image

updated 2012-07-30 05:37:01 -0500

target_link_libraries(prom2ROS ~/simulateur/lib/Linux/comm/libcomm_debug)

This is probably what isn't working for you. You've already specified the library search path with:


target_link_libraries now needs the individual library names you want to link, without the paths. This:

target_link_libraries(prom2ROS comm_debug)

would probably be enough.

Besides that, there some things I'd do differently:

  • don't use relative paths, they are dependent on the cwd, which is fragile (not in this case, but in general they are)
  • try to use an existing FindXXX script (or write one, in this case for the libraries and include paths of your simulator)
  • if not available / desirable / possible, try to use find_library, find_path, etc, instead of hard coding their locations

EDIT: Oops, forgot to remove the lib prefix from the library. Updated my answer above.

edit flag offensive delete link more


If you are a bit daring, you could also build your library with cmake and then you should be able to include that directly with catkin.

dornhege gravatar image dornhege  ( 2012-07-30 05:23:18 -0500 )edit

I'm gonna check for these find methods. That would be better than theses explicit paths (but the simulator is usually installed at user's root, even if it could change). May the "~ " be also a problem ?

Erwan R. gravatar image Erwan R.  ( 2012-07-30 05:35:50 -0500 )edit

In that case I'd advise to use "the intended" method, whatever that is, for users to discover the library. If it is installed system-wide, as a normal package, standard include/linker paths might suffice.

dornhege gravatar image dornhege  ( 2012-07-30 23:52:20 -0500 )edit

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: 2012-07-30 04:29:50 -0500

Seen: 11,332 times

Last updated: Jul 30 '12