Error for catkin_make even after adding target_link_libraries
Hi all,
I went through many posts and found that by adding targetlinklibraries the error which looks like following, stops.
CMakeFiles/visual_par.dir/src/visual_par.cpp.o: In function `main':
visual_par.cpp:(.text+0x55): undefined reference to `ros::init(int&, char**, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
visual_par.cpp:(.text+0x9f): undefined reference to `ros::NodeHandle::NodeHandle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)'
visual_par.cpp:(.text+0xc6): undefined reference to `ros::NodeHandle::~NodeHandle()'
visual_par.cpp:(.text+0x123): undefined reference to `ros::NodeHandle::~NodeHandle()'
visual_par.cpp:(.text+0x151): undefined reference to `ros::NodeHandle::~NodeHandle()'
collect2: ld returned 1 exit status
make[2]: *** [/home/parshad/hydro_workspace/devel/lib/visual_par/visual_par] Error 1
make[1]: *** [visual_par/CMakeFiles/visual_par.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
However I am still getting the error.
CMakefile:
cmake_minimum_required(VERSION 2.8.3)
project(visual_par)
find_package(catkin REQUIRED COMPONENTS roscpp visualization_msgs)
catkin_package(
# INCLUDE_DIRS include
CATKIN_DEPENDS roscpp visualization_msgs
)
${catkin_INCLUDE_DIRS}
)
add_executable(visual_par src/visual_par.cpp)
target_link_libraries(visual_par ${catkin_LIBRARIES})
package.xml:
<?xml version="1.0"?>
<package>
<name>visual_par</name>
<version>0.0.0</version>
<description>The visual_par package</description>
<maintainer email="name@todo.todo">parshad</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>visualization_msgs</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>visualization_msgs</run_depend>
<export>
</export>
</package>
I am trying to run following tutorial on visual markers:
#include <ros/ros.h>
#include <visualization_msgs/Marker.h>
#include <cmath>
int main( int argc, char** argv )
{
ros::init(argc, argv, "visual_par");
ros::NodeHandle n;
ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 10);
ros::Rate r(30);
float f = 0.0;
while (ros::ok())
{
visualization_msgs::Marker points, line_strip, line_list;
points.header.frame_id = line_strip.header.frame_id = line_list.header.frame_id = "/my_frame";
points.header.stamp = line_strip.header.stamp = line_list.header.stamp = ros::Time::now();
points.ns = line_strip.ns = line_list.ns = "points_and_lines";
points.action = line_strip.action = line_list.action = visualization_msgs::Marker::ADD;
points.pose.orientation.w = line_strip.pose.orientation.w = line_list.pose.orientation.w = 1.0;
points.id = 0;
line_strip.id = 1;
line_list.id = 2;
points.type = visualization_msgs::Marker::POINTS;
line_strip.type = visualization_msgs::Marker::LINE_STRIP;
line_list.type = visualization_msgs::Marker::LINE_LIST;
// POINTS markers use x and y scale for width/height respectively
points.scale.x = 0.2;
points.scale.y = 0.2;
// LINE_STRIP/LINE_LIST markers use only the x component of scale, for the line width
line_strip.scale.x = 0.1;
line_list.scale.x = 0.1;
// Points are green
points.color.g = 1.0f;
points.color.a = 1.0;
// Line strip is blue
line_strip.color.b = 1.0;
line_strip.color.a = 1.0;
// Line list is red
line_list.color.r = 1.0;
line_list.color.a = 1.0;
// Create the vertices for the points and lines
for (uint32_t i = 0; i < 100; ++i)
{
float y = 5 * sin(f + i / 100.0f * 2 * M_PI);
float z = 5 * cos(f + i / 100.0f * 2 * M_PI);
geometry_msgs::Point p;
p.x = (int32_t)i - 50;
p.y = y;
p.z = z;
points.points.push_back(p);
line_strip.points.push_back(p);
// The line list needs two points for each line
line_list.points.push_back(p);
p.z += 1.0;
line_list.points.push_back(p);
}
marker_pub.publish(points);
marker_pub.publish(line_strip);
marker_pub.publish(line_list);
r.sleep();
f += 0.04;
}
}
Moreover this error has started to appear for all my other packages. I am not sure what is the reason. Please suggest a solution.
Asked by djano_p on 2015-03-29 18:56:17 UTC
Comments
What's the output of
$ locate libroscpp
Asked by BennyRe on 2015-03-30 03:27:49 UTC