Hello all,
I am actually trying to complete the Exercise 3.1 of Unit 3. I created the package topic_publisher_pkg according to the instructions given in the previous Unit. However, when I try to build using
$ catkin_make, it raises the error: fatal error: ros/ros.h: No such file or directory
Thank you for your reply.
I tried following those steps but I still get the same error as before when I compile the packages.
The catkin_* variables are still empty.
That is strange. Could you post the entire error output from your terminal so I can better understand your situation. I need to know what you are doing that causes this issue.
Please copy-paste all of the terminal messages on which you see this error as a text data (not as an image / screenshot).
I did some cross-checking and noticed that your CMakeLists.txt file is fine. There are no issues there.
Your package.xml might be missing a dependency.
Try uncommenting only this line in your CMakeLists.txt file:
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES topic_publisher_pkg
CATKIN_DEPENDS roscpp std_msgs # <--- uncomment only this line
# DEPENDS system_lib
)
If this solution does not work, then post your package.xml file also.
Are you sure you are compiling your package(s) only inside ~/catkin_ws?
Your package.xml file also looks fine. There are no issues.
Your issue seems weird, since other posts that refer to the same issue in the internet seems helpless in your case.
I just have one final method: Remove and re-create catkin_ws. Follow the steps below:
Make a backup of all the packages that you have inside ~/catkin_ws/src folder. You can right-click on the src folder and choose “Download” to save the folders into your personal computer.
Remove the catkin_ws directory [after taking the backups in step 1].
cd ~
rm -rf ./catkin_ws
Refresh the course webpage by clicking on the refresh button on your internet browser.
Create catkin_ws again:
cd ~
mkdir -p ./catkin_ws/src
cd ~/catkin_ws
catkin_make
source devel/setup.bash
Now copy the backed-up files that you downloaded in step 1, back into ~/catkin_ws/src in the course IDE. Right-click on src folder in the IDE and select “Upload files” and choose the file(s) from your computer.
Extract the files if you downloaded them as compressed file.
Once you have uploaded (and extracted) your backup files, re-run catkin_make:
cd ~/catkin_ws
catkin_make
source devel/setup.bash
This time you should have no issues. In case you still have issues, please report here.
I removed and re-created the whole catkin_ws workspace.
Then I added the roscpp and std_msgs packages and the files they contained.
To be sure, I created the package topic_publisher_pkg using the command line $ catkin_create_pkg.
After compiling, everything was working well.
But as soon as I added the C++ file, the compiler raised the same fatal error: ros/ros.h: No such file or directory .
However, when I hover my mouse over the line #include <ros/ros.h> in the IDE, the correct path to the library /opt/ros/noetic/include/ros/ros.h is given.
I don’t understand what this means. Could you please clarify?
Did you create the package with the right command and in the right folder:
cd ~/catkin_ws/src
catkin_create_pkg topic_publisher_pkg roscpp std_msgs
Also, please share the structure of your workspace showing the package, by taking a screenshot of the IDE, expanding all the folders concerned. See an example below:
As Girish suggested, I downloaded the src directory before erasing catkin_ws.
When I recreated catkin_ws, I added the roscpp and std_msgs packages by hand. The ones I downloaded beforehand contained two files: CMakeLists.txt and package.xml so I added them.
Command line to create topic_publisher_pkg package:
WOW, I see one problem already! Please remove the two folders above topic_publisher_pkg; they are definitely causing problems! Remove the folders and everything inside them.
roscpp
std_msgs
After that, recompile the workspace:
cd ~/catkin_ws
rm -rf build/ devel/
catkin_make
source devel/setup.bash
Please send another screenshot showing your catkin_ws and topic_publisher_pkg, similar to what I have in my screenshot.
If you still have problems after that
Delete the package and create it again from scratch. You can make it work gust by following the hints given in the exercise. Nothing more.