0
$\begingroup$

Rosanswers logo

Hi.. I"m trying to compile the fibonacciServer.cpp code shown on the tutorial for the actionlib SimpleActionServer(ExecuteCallbackMethod) page. I've created the action file per the instructions and have copied the CMakeList.txt from the tutorial listing to the package. However, I get a compile error when trying to use the catkin_make command. Here are the errors:

Linking CXX executable /home/mark/devel/catkin_ws/devel/lib/learning_actionlib/fibonacci_server
CMakeFiles/fibonacci_server.dir/action/fibonacci_server.cpp.o: In function `actionlib::ActionServerBase<learning_actionlib::FibonacciAction_<std::allocator<void> > >::ActionServerBase(boost::function<void (actionlib::ServerGoalHandle<learning_actionlib::FibonacciAction_<std::allocator<void> > >)>, boost::function<void (actionlib::ServerGoalHandle<learning_actionlib::FibonacciAction_<std::allocator<void> > >)>, bool)':
fibonacci_server.cpp:(.text._ZN9actionlib16ActionServerBaseIN18learning_actionlib16FibonacciAction_ISaIvEEEEC2EN5boost8functionIFvNS_16ServerGoalHandleIS4_EEEEESB_b[_ZN9actionlib16ActionServerBaseIN18learning_actionlib16FibonacciAction_ISaIvEEEEC5EN5boost8functionIFvNS_16ServerGoalHandleIS4_EEEEESB_b]+0xa5): undefined reference to `actionlib::GoalIDGenerator::GoalIDGenerator()'
CMakeFiles/fibonacci_server.dir/action/fibonacci_server.cpp.o: In function `actionlib::StatusTracker<learning_actionlib::FibonacciAction_<std::allocator<void> > >::StatusTracker(boost::shared_ptr<learning_actionlib::FibonacciActionGoal_<std::allocator<void> > const> const&)':
fibonacci_server.cpp:(.text._ZN9actionlib13StatusTrackerIN18learning_actionlib16FibonacciAction_ISaIvEEEEC2ERKN5boost10shared_ptrIKNS1_20FibonacciActionGoal_IS3_EEEE[_ZN9actionlib13StatusTrackerIN18learning_actionlib16FibonacciAction_ISaIvEEEEC5ERKN5boost10shared_ptrIKNS1_20FibonacciActionGoal_IS3_EEEE]+0x60): undefined reference to `actionlib::GoalIDGenerator::GoalIDGenerator()'
fibonacci_server.cpp:(.text._ZN9actionlib13StatusTrackerIN18learning_actionlib16FibonacciAction_ISaIvEEEEC2ERKN5boost10shared_ptrIKNS1_20FibonacciActionGoal_IS3_EEEE[_ZN9actionlib13StatusTrackerIN18learning_actionlib16FibonacciAction_ISaIvEEEEC5ERKN5boost10shared_ptrIKNS1_20FibonacciActionGoal_IS3_EEEE]+0xbb): undefined reference to `actionlib::GoalIDGenerator::generateID()'
CMakeFiles/fibonacci_server.dir/action/fibonacci_server.cpp.o: In function `actionlib::StatusTracker<learning_actionlib::FibonacciAction_<std::allocator<void> > >::StatusTracker(actionlib_msgs::GoalID_<std::allocator<void> > const&, unsigned int)':
fibonacci_server.cpp:(.text._ZN9actionlib13StatusTrackerIN18learning_actionlib16FibonacciAction_ISaIvEEEEC2ERKN14actionlib_msgs7GoalID_IS3_EEj[_ZN9actionlib13StatusTrackerIN18learning_actionlib16FibonacciAction_ISaIvEEEEC5ERKN14actionlib_msgs7GoalID_IS3_EEj]+0x5c): undefined reference to `actionlib::GoalIDGenerator::GoalIDGenerator()'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/mark/devel/catkin_ws/devel/lib/learning_actionlib/fibonacci_server] Error 1
make[1]: *** [learning_actionlib/CMakeFiles/fibonacci_server.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

To my mind and another programmer more experienced in using the older rosbuild, it appears that the include path is not set correctly.

Thanks for any help

Mark

fibonacci_server.cpp

#include <ros/ros.h>
#include <actionlib/server/simple_action_server.h>
#include <learning_actionlib/FibonacciAction.h>

class FibonacciAction
{
protected:

  ros::NodeHandle nh_;
  // NodeHandle instance must be created before this line. Otherwise strange error may occur.
  actionlib::SimpleActionServer<learning_actionlib::FibonacciAction> as_; 
  std::string action_name_;
  // create messages that are used to published feedback/result
  learning_actionlib::FibonacciFeedback feedback_;
  learning_actionlib::FibonacciResult result_;

public:

  FibonacciAction(std::string name) :
    as_(nh_, name, boost::bind(&FibonacciAction::executeCB, this, _1), false),
    action_name_(name)
  {
    as_.start();
  }
FibonacciAction(void)
  {
  }

  void executeCB(const learning_actionlib::FibonacciGoalConstPtr &goal)
  {
    // helper variables
    ros::Rate r(1);
    bool success = true;

    // push_back the seeds for the fibonacci sequence
    feedback_.sequence.clear();
    feedback_.sequence.push_back(0);
    feedback_.sequence.push_back(1);

    // publish info to the console for the user
    ROS_INFO("%s: Executing, creating fibonacci sequence of order %i with seeds %i, %i", action_name_.c_str(), goal->order, feedback_.sequence[0], feedback_.sequence[1]);

    // start executing the action
    for(int i=1; i<=goal->order; i++)
    {
      // check that preempt has not been requested by the client
      if (as_.isPreemptRequested() || !ros::ok())
      {
        ROS_INFO("%s: Preempted", action_name_.c_str());
        // set the action state to preempted
        as_.setPreempted();
        success = false;
        break;
      }
      feedback_.sequence.push_back(feedback_.sequence[i] + feedback_.sequence[i-1]);
      // publish the feedback
      as_.publishFeedback(feedback_);
      // this sleep is not necessary, the sequence is computed at 1 Hz for demonstration purposes
      r.sleep();
    }
if(success)
    {
      result_.sequence = feedback_.sequence;
      ROS_INFO("%s: Succeeded", action_name_.c_str());
      // set the action state to succeeded
      as_.setSucceeded(result_);
    }
  }


};


int main(int argc, char** argv)
{
  ros::init(argc, argv, "fibonacci");

  FibonacciAction fibonacci(ros::this_node::getName());
  ros::spin();

  return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(learning_actionlib)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  actionlib_msgs
  roscpp
  rospy
  )
find_package(Boost REQUIRED COMPONENTS system)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependencies might have been
##     pulled in transitively but can be declared for certainty nonetheless:
##     * add a build_depend tag for "message_generation"
##     * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
add_action_files(
#    DIRECTORY action
    FILES
    Fibonacci.action
#   Action2.action
 )

## Generate added messages and services with any dependencies listed here
  generate_messages(
    DEPENDENCIES
    actionlib_msgs   
  )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
 INCLUDE_DIRS include 
#  LIBRARIES learning_actionlib
  CATKIN_DEPENDS actionlib actionlib_msgs message_generation roscpp rospy std_msgs
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
)

## Declare a cpp library
#add_library(learning_actionlib
#   src/${PROJECT_NAME}/learning_actionlib.cpp
# )

Originally posted by mmckenna on ROS Answers with karma: 11 on 2015-06-17

Post score: 1


Original comments

Comment by dornhege on 2015-06-17:
What is your code? This doesn't look like a include path error at all.

Comment by mmckenna on 2015-06-17:
I edited the question to add the code for fibonnacci_server.cpp and the CMakeLists.txt files.

Comment by Javier V. Gómez on 2015-06-18:
The first error says

Error: no matching function for call to ‘actionlib::SimpleActionServer<learning_actionlib::FibonacciAction_<std::allocator<void>>>::SimpleActionServer()’

Why is there an underscore in FibonacciAction_? Do you have a typo somewhere?

Comment by mmckenna on 2015-06-18:
Hi Javi. thank you for repsonding. If this was code I created, then I can see many opportunities for typos. However, I copied both the cpp and the CMakeLists.txt from the http://wiki.ros.org/actionlib_tutorials/Tutorials/SimpleActionServer%28ExecuteCallbackMethod%29 tutorial page, without changes

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

The problem is the extra empty constructor that you added. This calls the default constructor of the action server, which does not exist.


Originally posted by dornhege with karma: 31395 on 2015-06-18

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by mmckenna on 2015-06-18:
Hi Dornhenge: thank you for replying. I commented out the second empty constructor and get the same error messages.

Comment by dornhege on 2015-06-18:
Show the exact code and error messages.

Comment by mmckenna on 2015-06-18:
Errors posted above in a revision to original post. Code is posted there and taken directly from http://wiki.ros.org/actionlib_tutorials/Tutorials/SimpleActionServer%28ExecuteCallbackMethod%29

Comment by dornhege on 2015-06-18:
The new errors are completely different. You are probably missing a dependency or target_link_libraries in your CMakeLists.txt

Comment by AdamSorrel on 2018-04-05:
Update from the future :-). The empty class constructor is actually supposed to be a class desctructor with the tilde somehow lost in the copying. Also it isn't connected to the problem. The correct solution is adding actionlib into find_package (as described bellow by tonka46).

$\endgroup$
0
$\begingroup$

Rosanswers logo

check your CMakeLists.txt and make sure you have actionlib and actionlib_msg in both catkin_package and find_package macro's

Also make sure that in your package.xml file you have <build_depend>actionlib</build_depend> <run_depend>actionlib</run_depend> <build_depend>actionlib_msgs</build_depend> <run_depend>actionlib_msgs</run_depend>


Originally posted by gguy1 with karma: 51 on 2016-11-16

This answer was NOT ACCEPTED on the original site

Post score: 4


Original comments

Comment by tonka46 on 2017-06-21:
incase someone else comes across this actionlib needs to be added to find_package not catkin_package, this was missing in the tutorial.

Comment by eng_hish on 2021-07-13:
Thank you so much. This has solved my issue

$\endgroup$

Your Answer

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