0
$\begingroup$

Rosanswers logo

hello, when I run catkin_make I get the following errors:

Scanning dependencies of target gira
[100%] Building CXX object prueba/CMakeFiles/gira.dir/src/gira.cpp.o
Linking CXX executable /home/turtlebot/catkin_ws/devel/lib/proyecto/gira
CMakeFiles/gira.dir/src/gira.cpp.o: In function `main':
gira.cpp:(.text+0x55): undefined reference to `ros::init(int&, char**, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
gira.cpp:(.text+0xa5): undefined reference to `ros::NodeHandle::NodeHandle...

any idea what could be the mistake? thanks

the executable gira.cpp:

#include "ros/ros.h"   
#include "geometry_msgs/Twist.h"  

int main(int argc, char **argv)
{

ros::init(argc, argv, "gira");   

    ros::NodeHandle n;

    ros::Publisher vel_pub_=n.advertise<geometry_msgs::Twist>("cmd_vel", 1);   

    geometry_msgs::Twist vel;

    ros::Rate loop_rate(10);   

    while (ros::ok())   
    {
        vel.linear.x = 0.1;   //velocidad de avance
        vel.angular.z = 0.3;   //velocidad de giro

        vel_pub_.publish(vel);

        loop_rate.sleep();
    }

    return 0;
}

the CMakeLists.txt (catkin specific configuration and built) :

cmake_minimum_required(VERSION 2.8.3) project(prueba)

find_package(catkin REQUIRED COMPONENTS geometry_msgs image_transport nav_msgs roscpp sensor_msgs std_msgs )

catkin_package( INCLUDE_DIRS include

LIBRARIES prueba

CATKIN_DEPENDS geometry_msgs image_transport nav_msgs roscpp sensor_msgs std_msgs turtlebot_node

DEPENDS system_lib

)

Specify additional locations of header files

Your package locations should be listed before other locations

include_directories(include ${catkin_INCLUDE_DIRS} )

Declare a cpp library

add_library(prueba

src/${PROJECT_NAME}/prueba.cpp

)

Declare a cpp executable

add_executable(prueba_node src/prueba_node.cpp)

add_executable(gira src/gira.cpp)

Add cmake target dependencies of the executable/library

as an example, message headers may need to be generated before nodes

add_dependencies(prueba_node prueba_generate_messages_cpp)

Specify libraries to link a library or executable target against

target_link_libraries(prueba_node

${catkin_LIBRARIES}

)


Originally posted by albarranco on ROS Answers with karma: 11 on 2013-07-15

Post score: 0


Original comments

Comment by Asfandyar Ashraf Malik on 2013-07-15:
It seems that the problem is with your code. Without the code, its quite hard to figure out the solution to this problem

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Undefined references indicate linker problems. It seems like the linker cannot find any ROS related symbols. Are you sure you have your package.xml and CMakeLists.txt setup properly?


Originally posted by ipso with karma: 1416 on 2013-07-15

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by albarranco on 2013-07-16:
I've only added to CMakeLists.txt add_executable(gira src/gira.cpp). Do I have to change something else in the CMakeLists.txt or package.xml?

Comment by ipso on 2013-07-16:
Then please post the contents of your CMakeLists.txt (add it to your original question).

Comment by albarranco on 2013-10-18:
Solved, I forgot to add target_link_libraries (gira $ {catkin_LIBRARIES}) to CMakeList.txt. Thanks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.