Ask Your Question

How do I link an executable with library in other package?

asked 2012-05-11 03:25:04 -0500

Hancheol Choi gravatar image

updated 2012-05-13 15:08:31 -0500

I want to make an executable in a package referencing a library in another package. I succeeded making library(named test_utility), but failed to link with executable(named test_using_utility). I don't know what the problem is.

Here is my header and source files to make a library in test_utility package.

// ros_workspace/test_utility/include/test_utility/test_utility.hpp
#ifndef _TEST_UTILITY_
#define _TEST_UTILITY_

class Utility 
    float dosomething(float);


// ros_workspace/test_utility/src/test_utility.cpp
#include <test_utility/test_utility.hpp>

float Utility::dosomething(float p)
    return p/2;

I added this comment in CMakeLists.txt

rosbuild_add_library(test_utility src/test_utility.cpp)

and it's manifest.xml

  <description brief="test_utility">


  <eview status="unreviewed" notes=""/>
  <depend package="roscpp"/>
  <depend package="std_msgs"/>
    <cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -ltest_utility"/> 

Here is my source file in executable in test_using_utility package.

// ros_workspace/test_using_utility/src/test_using_utility.cpp
#include <ros/ros.h>
#include <test_utility/test_utility.hpp>
#include <iostream>

int main(int argc, char** argv)
    ros::init(argc, argv, "test");
    ros::NodeHandle nh;

    Utility u;
    float x = u.dosomething(32);

    std::cout << x << std::endl;

    return 0;

I added in CMakeLists.txt

rosbuild_add_executable(test_using_utility src/test_using_utility.cpp)

also, it's manifest.xml

  <description brief="test_using_utility">


  <review status="unreviewed" notes=""/>
  <depend package="roscpp"/>
  <depend package="std_msgs"/>
  <depend package="test_utility"/>

Finally, I got an link error like this when rosmaking in test_using_utility package.

[ rosmake ] rosmake starting...                                                 
[ rosmake ] No package specified.  Building ['test_using_utility']              
[ rosmake ] Packages requested are: ['test_using_utility']                      
[ rosmake ] Logging to directory /home/babchol/.ros/rosmake/rosmake_output-20120512-092758
[ rosmake ] Expanded args ['test_using_utility'] to:
[rosmake-0] Starting >>> roslang [ make ]                                       
[rosmake-1] Starting >>> std_msgs [ make ]                                      
[rosmake-0] Finished <<< roslang ROS_NOBUILD in package roslang
 No Makefile in package roslang
[rosmake-0] Starting >>> roscpp [ make ]                                        
[rosmake-1] Finished <<< std_msgs ROS_NOBUILD in package std_msgs
 No Makefile in package std_msgs
[rosmake-0] Finished <<< roscpp ROS_NOBUILD in package roscpp
 No Makefile in package roscpp
[rosmake-0] Starting >>> test_utility [ make ]                                  
[rosmake-0] Finished <<< test_utility [PASS] [ 2.52 seconds ]                   
[rosmake-0] Starting >>> test_using_utility [ make ]                            
[ rosmake ] Last 40 linesst_using_utility: 1.5 sec ]   [ 1 Active 4/5 Complete ]
    source dir.  Run "cmake --help-policy CMP0015" for policy details.  Use the
    cmake_policy command to set the policy and suppress this warning.
  Call Stack (most recent call first):
    CMakeLists.txt:12 (rosbuild_init)
  This warning is for project developers.  Use -Wno-dev to suppress it.

  [rosbuild] Including /opt/ros/fuerte/share/roslisp/rosbuild/roslisp.cmake
  [rosbuild] Including /opt/ros/fuerte/share/rospy/rosbuild/rospy.cmake
  [rosbuild] Including /opt/ros/fuerte/share/roscpp/rosbuild/roscpp.cmake
  -- Configuring done
  -- Generating done
  CMake Warning:
    Manually-specified variables were not used by the project:


  -- Build files have been written to: /home/babchol/ros_workspace/test_using_utility/build
  cd build && make -l2
  make[1]: Entering directory `/home/babchol/ros_workspace/test_using_utility/build'
  make[2]: Entering directory `/home/babchol/ros_workspace/test_using_utility/build'
  make[3]: Entering directory `/home/babchol/ros_workspace/test_using_utility/build'
  make[3]: Leaving directory `/home/babchol/ros_workspace ...
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2012-05-11 03:34:34 -0500

Lorenz gravatar image

updated 2012-05-13 04:07:48 -0500

The export in your manifest file should be:

   <cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -ltest_utility"/>

This will add your library to the list of libraries to link against.

Edit: It looks like you have a typo in your manifest export, a { is missing after -L. Make sure that it looks exactly as my code above.

edit flag offensive delete link more


Wow! It's my terrible mistake. Anyway, thank you. all solved.

Hancheol Choi gravatar image Hancheol Choi  ( 2012-05-13 14:43:59 -0500 )edit

answered 2012-05-11 08:04:48 -0500

tfoote gravatar image

The manifest export provides linking instructions for packages which depend on your package. If you are still inside the same package as the library you need to use the cmake command to link the library:

target_link_library(test_using_utility test_utility)
edit flag offensive delete link more


I already tested this in same package, and succeeded. But I want to reference library in other package.

Hancheol Choi gravatar image Hancheol Choi  ( 2012-05-11 14:34:43 -0500 )edit

answered 2012-05-11 05:14:46 -0500

Hancheol Choi gravatar image

I know I have to comment for discussions, but I can't find comment icon under the replied answer. So, I have to write feedback here.

I added -ltest_utility in my manifest file as Lorenz said. But I still have error like this; cannot find -ltest_utility

Is there additional solution?

edit flag offensive delete link more



You need a certain amount of karma to comment. Can you please edit your question and provide both manifest files of your packages?

Lorenz gravatar image Lorenz  ( 2012-05-11 05:24:11 -0500 )edit

I editted my original question. added full manifest.xml files and error.

Hancheol Choi gravatar image Hancheol Choi  ( 2012-05-11 14:30:45 -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-05-11 03:25:04 -0500

Seen: 4,493 times

Last updated: May 13 '12