Actionlib Tutorials: cmake can't find Action.h file
Hi,
I'm getting started learning actionlib, and have the example from the tutorials working just fine, and I thought I understood it pretty well. I'm trying to implement a second server (Called counter_server, based on a Counter.action file) so I can learn it better, and am having some trouble.
Quick note, running ROS melodic in ubuntu 18.04 in a VMware VM.
When compiling, this is the error I get:
/home/me/catkinws/src/actionlibtutorials/src/counterserver.cpp:3:10: fatal error: actionlibtutorials/CounterAction.h: No such file or directory
#include <actionlib_tutorials/CounterAction.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
actionlib_tutorials/CMakeFiles/counter_server.dir/build.make:62: recipe for target 'actionlib_tutorials/CMakeFiles/counter_server.dir/src/counter_server.cpp.o' failed
make[2]: *** [actionlib_tutorials/CMakeFiles/counter_server.dir/src/counter_server.cpp.o] Error 1
CMakeFiles/Makefile2:481: recipe for target 'actionlib_tutorials/CMakeFiles/counter_server.dir/all' failed
make[1]: *** [actionlib_tutorials/CMakeFiles/counter_server.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j1 -l1" failed
I suspect some sort of a cmake error. This is all of my CMakeLists:
cmake_minimum_required(VERSION 2.8.3)
project(actionlib_tutorials)
find_package(catkin REQUIRED COMPONENTS
actionlib
actionlib_msgs
message_generation
roscpp
rospy
std_msgs
)
add_action_files(
DIRECTORY
action
FILES
Counter.action
Fibonacci.action
)
generate_messages(
DEPENDENCIES
actionlib_msgs std_msgs
)
catkin_package(
CATKIN_DEPENDS actionlib_msgs
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
add_executable(fibonacci_server src/fibonacci_server.cpp)
target_link_libraries(
fibonacci_server
${catkin_LIBRARIES}
)
add_dependencies(
fibonacci_server
${fibonacci_server_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)
add_executable(counter_server src/counter_server.cpp)
target_link_libraries(
counter_server
${catkin_LIBRARIES}
)
add_dependencies(
counter_server
${counter_server_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)
This is the code in counter_server.cpp, but it seems like pretty straightforward C++ and is extremely similar to the code from the tutorial.
#include <ros/ros.h>
#include <actionlib/server/simple_action_server.h>
#include <actionlib_tutorials/CounterAction.h>
class CounterAction{
protected:
ros::NodeHandle nh_;
actionlib::SimpleActionServer<actionlib_tutorials::CounterAction> as_;
std::string action_name_;
actionlib_tutorials::CounterFeedback feedback_;
actionlib_tutorial::CounterResult result_
public:
CounterAction(std::string name): as_(nh, name, boost::bind(&FibonacciAction::executeCB, this, 1),false),
action_name_(name){
as_.start();
}
~FibonacciAction(void){}
void executeCB(const actionlib_tutorials::CounterGoalConstPtr& goal){
ros::Rate r(1);
bool success = true;
int sum = 0;
ROS_INFO("Starting counter");
for(int i = 0; i < goal->maxVal; ++i){
if(as_.isPreeptRequested() || !ros::ok()){
ROS_INFO("Preempted");
as_.setPreempted;
success = false;
break;
}
sum += i;
feedback_.currentVal = i;
as_.publishFeedback(feedback_);
r.sleep();
}
if(success){
result_.sum = sum;
ROS_INFO("yay did a count");
as_.setSucceeded(result_);
}
}
};
int main(int arcg, char** argv){
ros::init(argc, argv, "counter");
CounterAction counter("counter");
ros::spin();
return 0;
}
)
I hope you can help! Thanks!
Asked by sethgi on 2019-01-14 23:38:57 UTC
Answers
So, it turns out my dependencies were wrong! Here’s how I found out:
After a make clean, I would build and it would fail, then build again and it worked. So I checked if the files were there, and it only could compile if the files were there before compiling. This indicates bad dependencies. It turns out my exported targets tag was wrong. Instead of:
Counter_server_EXPORTED_TARGETS
It needs to be
${PROJECT_NAME}_EXPORTED_TARGETS
Problem solved, it builds first time after cleaning!
Asked by sethgi on 2019-01-15 15:33:31 UTC
Comments
Can you add the full
CMakeList.txt
please ? Just a few remarks here :It seems to be missing
DIRECTORY action
Asked by Delb on 2019-01-15 02:44:42 UTC
Your executeCB is within the scope of the FibonacciAction class, should be CounterAction. And you have typos here :
actionlib_tutorial::CounterResult result_
, missing;
and as
at actionlib_tutorials.Asked by Delb on 2019-01-15 02:46:10 UTC
in CMakeList, check that the catkin directory is included:
Asked by mali on 2019-01-15 04:15:16 UTC
I've made all the changed you all suggested (but include_directories(...) was already in my cmakelists) and still nothing! I've uploaded my full cmakelists in the hope it helps. And thanks @delb for catching some C++ typos, but it of course hadn't gotten to compiling that anyways. Thanks!
Asked by sethgi on 2019-01-15 11:12:18 UTC
ok I have no clue what I changed but suddenly it built... disappointing and I can't break it even by undoing stuff a bunch! I did a make clean and rebuild but the files existed in the first case, it just couldn't find them. So it's weird.
Asked by sethgi on 2019-01-15 15:32:42 UTC
I've also seen this behavior ( => always failing at the first catkin_make and no error at the second). Does it compiles again if you delete your
build
anddevel
folders ?Asked by Delb on 2019-01-16 04:29:38 UTC
typically a symptom of a build script missing
add_dependencies(..)
.Asked by gvdhoorn on 2019-01-16 04:31:28 UTC
Yes, that was exactly one of my issues as the second answer of #q288890 suggested.
Asked by Delb on 2019-01-16 04:36:32 UTC
See my edited answer! Pretty much what y’all were saying
Asked by sethgi on 2019-01-16 11:10:28 UTC