ERROR: cannot launch node of type [...]: Cannot locate node of type [....] in package [....]

I just wanted to ask some clarifications to see if I understand this correctly.

The issue of this error :

The problem is that your C++ executable has not been compiled even if everything appears to be correctly setup.

The way I solve this issue is by using the project name the same as my executable file in which case :

If my executable file name is executable_file.cpp, then my PROJECT_NAME is also executable_file.

As taken from ROS official documentation:

 add_dependencies(some_target ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

So, in my case, it is:

 add_dependencies(executable_file ${executable_file_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

Is my understanding correct?

Also, I came across the solution where I have to either use :

rm -rf build/ devel/ //or even 
catkin clean

to solve the issue of C++ file not compiling.

Why is that so? I avoided using catkin clean as it gives me warning that it will delete the logs, build and devel directory which I dont know if it will cause an issue in the long run.


Yes it is good practice to name your project the same as your exectuable, although it doesn’t matter once you have more than one.

As for the removal of your build and devel folders, this wouldn’t cause an issue, basically you generate these folders every time you compile

Given the case that I decided to use “main” as the name of my executable. Am I correct that once it compile, it will compile and create my executable file inside the:


and as shown in the below diagram?

So, if I want to launch this executable file using roslaunch, I’ll need to put the name of my executable file in the type parameter and NOT its .cpp file, correct?

    <node pkg="topics_quiz" type="main" name="topics_quiz_node" output="screen"/>

Sorry for the weird question, its just that I tend to get confuse with this concept because in ROS for python course, I’d put its ‘.py’ file instead.

That should be it. For C++ what you use in your launch file should be the script.cpp minus the .cpp part.