ERROR: cannot launch node of type [topic_publisher_pkg /simple_topic_publisher]: topic_publisher_pkg

I am facing this error in Unit 3, and I have tried to do several things to solve the error

first:
CMakeList:

add_executable(simple_topic_publisher src/simple_topic_publisher.cpp)

add_dependencies(simple_topic_publisher ${simple_topic_publisher_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(simple_topic_publisher

${catkin_LIBRARIES}


)

###########

## Specify additional locations of header files

## Your package locations should be listed before other locations

include_directories(

# include

${catkin_INCLUDE_DIRS}

)

Launch File

<launch>
  <node pkg="topic_publisher_pkg " type="simple_topic_publisher" name="topic_publisher"  output="screen">
  </node>
</launch>

Tried Solutions

  1. I made sure all the names were exactly the same by copying file names
  2. When doing catkin make there were no errors
  3. I tried to remove build and devel

run from catkin_ws directory

rm -rf build/ devel/
cakin_make
source devel/setup.bash
4) I tried writing manually the cmake list which I did not fully understand why, but was mentioned in solutions
5) Finally I ran the cpp file via rosrun and it ran, but I know this is not a good solution

Not sure what to do

##########################################################################

user:~/catkin_ws$ roslaunch topic_publisher_pkg topic_publisher_pkg_launch_file.launch
… logging to /home/user/.ros/log/a759fb10-ac16-11ed-b95e-0242c0a82006/roslaunch-3_xterm-11187.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://3_xterm:42215/

SUMMARY

PARAMETERS

  • /rosdistro: noetic
  • /rosversion: 1.15.9

NODES
/
nh (topic_publisher_pkg /simple_topic_publisher)

ROS_MASTER_URI=http://3_simulation:11311

ERROR: cannot launch node of type [topic_publisher_pkg /simple_topic_publisher]: topic_publisher_pkg
ROS path [0]=/opt/ros/noetic/share/ros
ROS path [1]=/home/user/catkin_ws/src
ROS path [2]=/home/simulations/public_sim_ws/src
ROS path [3]=/opt/ros/noetic/share
No processes to monitor
shutting down processing monitor…
… shutting down processing monitor complete

Hi @Ziad.Shoeib ,

Welcome to this Community!

If the contents of the CMakeLists.txt file is exactly as the one you have posted, then you are missing some commands in the file.

Could you please post the entire contents of your CMakeLists.txt file and your C++ program file as a code-block?

Regards,
Girish