How do I link an executable with library in other package?
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
{
public:
float dosomething(float);
};
#endif
// 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
<package>
<description brief="test_utility">
test_utility
</description>
<author>babchol</author>
<license>BSD</license>
<eview status="unreviewed" notes=""/>
<url>http://ros.org/wiki/test_utility</url>
<depend package="roscpp"/>
<depend package="std_msgs"/>
<export>
<cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -ltest_utility"/>
</export>
</package>
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;
ros::spin();
return 0;
}
I added in CMakeLists.txt
rosbuild_add_executable(test_using_utility src/test_using_utility.cpp)
also, it's manifest.xml
<package>
<description brief="test_using_utility">
test_using_utility
</description>
<author>babchol</author>
<license>BSD</license>
<review status="unreviewed" notes=""/>
<url>http://ros.org/wiki/test_using_utility</url>
<depend package="roscpp"/>
<depend package="std_msgs"/>
<depend package="test_utility"/>
</package>
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: ['test_using_utility'] [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: CMAKE_TOOLCHAIN_FILE -- 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 ...