ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Navigation Sending Simple Goal from Class

asked 2019-03-21 11:12:08 -0600

MarcoStb gravatar image

updated 2019-03-21 14:11:17 -0600

jayess gravatar image

Hi, I'm having trouble converting the Navigation Tutorial "SendingSimpeGoals" to a format where the functionality can be used out of a library. When splitting everything up into a h- and cpp-file I get the below errors when running "catkin_make".
If I replace the source code in node.cpp with the tutorial code, everything compiles and runs fine.

I built the minimum example below to show the error. I would appreciate any help, thank you in advance! I am running ROS Kinetic on Ubuntu 16.04 on a VMware Workstation.

Following, the error messages and the source code:

/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::ConnectionMonitor::goalConnectCallback(ros::SingleSubscriberPublisher const&)'
/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::ConnectionMonitor::goalDisconnectCallback(ros::SingleSubscriberPublisher const&)'
/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::GoalIDGenerator::generateID()'
/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::ConnectionMonitor::cancelDisconnectCallback(ros::SingleSubscriberPublisher const&)'
min_example/CMakeFiles/node.dir/build.make:115: recipe for target '/home/marco/catkin_ws/devel/lib/min_example/node' failed
CMakeFiles/Makefile2:2957: recipe for target 'min_example/CMakeFiles/node.dir/all' failed
Makefile:138: recipe for target 'all' failed
/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::ConnectionMonitor::ConnectionMonitor(ros::Subscriber&, ros::Subscriber&)'
/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::ConnectionMonitor::cancelConnectCallback(ros::SingleSubscriberPublisher const&)'
/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::ConnectionMonitor::waitForActionServerToStart(ros::Duration const&, ros::NodeHandle const&)'
/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::ConnectionMonitor::processStatus(boost::shared_ptr<actionlib_msgs::GoalStatusArray_<std::allocator<void> > const> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/marco/catkin_ws/devel/lib/libincluded_class.so: undefined reference to `actionlib::GoalIDGenerator::GoalIDGenerator()'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/marco/catkin_ws/devel/lib/min_example/node] Error 1
make[1]: *** [min_example/CMakeFiles/node.dir/all] Error 2
make: *** [all] Error 2
16:57:59: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Project (kit: Desktop)
When executing step "Make"

Here is my source code: CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(min_example)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
    actionlib
    move_base_msgs
    roscpp
    )

catkin_package(
    )

include_directories(
    include
    ${catkin_INCLUDE_DIRS}
    ../../devel/include
    )

add_library(included_class src/included_class.cpp)
add_executable(node src/node.cpp)


target_link_libraries(
    node
    ${catkin_LIBRARIES}
    included_class
    )

add_dependencies(included_class ${catkin_EXPORTED_TARGETS})
add_dependencies(node ${catkin_EXPORTED_TARGETS})

install(DIRECTORY config launch include
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

package.xml

<?xml version="1.0"?>
<package format="2">
<name>min_example</name>
<version>0.0.0</version>
<description>min_example</description>


<maintainer email="marco@todo.todo">marco</maintainer>

<license>TODO</license>


<buildtool_depend>catkin</buildtool_depend>
<build_depend>actionlib</build_depend>
<build_depend>move_base_msgs</build_depend>
<build_depend>roscpp</build_depend>
<build_export_depend>actionlib</build_export_depend>
<build_export_depend>move_base_msgs</build_export_depend>
<build_export_depend>roscpp</build_export_depend>
<exec_depend>actionlib</exec_depend>
<exec_depend>move_base_msgs</exec_depend>
<exec_depend>roscpp</exec_depend>

<export>

</export>
</package>

node.cpp

#include "ros/ros.h"
#include "included_class.h"

int main(int argc, char **argv)
{
    ros::init(argc, argv, "node");
    Included_Class included_class;
    return 0;
}

included_class.h

#include "ros/ros.h ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-03-22 05:45:52 -0600

MarcoStb gravatar image

updated 2019-04-06 19:03:26 -0600

jayess gravatar image

I managed to find a solution myself. The error was caused by using a wrong order for target_link_libraries. So, instead of listing ${catkin_LIBRARIES} first, included_class has to come first (see below code snippet).

...
target_link_libraries( node
    included_class
    ${catkin_LIBRARIES}
    )
...
edit flag offensive delete link more

Comments

Can someone please accept this as the answer, I don't have enough points? Thank you!

MarcoStb gravatar image MarcoStb  ( 2019-03-22 05:46:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-21 11:12:08 -0600

Seen: 459 times

Last updated: Apr 06 '19