Exercise 4.5 ROS Actions

inside the src folder the package action_client_pkg I created two cpp files namely wait_for_result_test.cpp and no_wait_for_result_test.cpp .

In Next step I added the code from tutorial and modified the CMakeLists.txt file as following:

I complied the package and encountered the following error:

I checked inside the src/action_client_pkg, which shows all the files.

I doubt either I am modifying my CMakeLists.txt wrongly? or I am doing mistake somewhere else?
Thank you for your suggestions in advance!!

Hi @bayodesegun!!
Sorry to tag you for this question directly.
Could you please suggest the correct way to compile this package?
Thank you very much for your help.

Hi @shaktigehlaut,

I was coming to your question - you just beat me to it! Please feel free to tag me directly any time - you are welcome!

Now, there is definitely some problem with CMakeLists.txt as indicated by the error messages. I can see one here:

  • in the add_dependencies directive, you should use the name of the package (NOT the C++ program) in the ...EXPORTED_TARGETS part. So for both executables, it should be action_client_pkg_EXPORTED_TARGETS.

The definition of that directive is (as you will find before modifying it):


Better not to modify the ...EXPORTED_TARGETS part, as the project name will be automatically “calculated” if you don’t touch it.

Please make this correction and let us know how it goes.

Hi @bayodesegun !!
Thanks for your suggestions.

in CMakeLists.txt as per directive


Should I use
add_executable(wait_for_result_test src/ wait_for_result_test.cpp) add_dependencies(action_client_pkg_node ${action_client_pkg_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) target_link_libraries(wait_for_result_test ${catkin_LIBRARIES} )

add_executable(wait_for_result_test src/ wait_for_result_test.cpp) add_dependencies(action_client_pkg_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) target_link_libraries(wait_for_result_test ${catkin_LIBRARIES} )

Hi @shaktigehlaut,

Any of the two will work! Please ensure you don’t have any unnecessary space as in src/ wait_for_result_test.cpp. Should be src/wait_for_result_test.cpp (no space after the /).

Hi @bayodesegun!!
Sorry for bothering you again.
I used the following CMakeLists.txt

But I am encountering error stating the non-existent target “action_client_pkg_node”

Hi @shaktigehlaut,

I think I confused you more, sorry :cold_sweat:. Let me clarify:

  • Let’s leave the 2nd argument of add_dependencies intact. So, please just put ${${PROJECT_NAME}_EXPORTED_TARGETS} everywhere you have the directive. I think that’s easier.
  • For all of them, you still need to modify the first argument, which is the name of your executable. So you need to change action_client_pkg_node to the exact name specified in the preceding add_executable directive, which should be wait_for_result_test and no_wait_for_result_test respectively.

@bayodesegun Thank you!!
It perfectly compiled the project.

1 Like