Also, I’ve checked the previous discussion on the exercise 5.2.1, which suggests the revision of the path and name of the header file. While the “No such file or directory” error still occurs after changing the header file title. I am wondering what the correct name and path for should be for the header.
Any further suggestions will be highly appreciated. Thanks in advance!
thank you very much for the error logs and the CMakeLists.txt file.
If the error is:
/home/user/catkin_ws/src/laser_reader/src/laser_reader.cpp:1:10: fatal error: laser_reader/laser_reader.h: No such file or directory
1 | #include "laser_reader/laser_reader.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Then, this means that you don’t have a file named laser_reader.sh inside a folder named laser_reader that is expected to be inside the /home/user/catkin_ws/src/laser_reader/include folder.
Since you are including laser_reader/laser_reader.h, the header file has to be inside a folder with the same name.
If your header file is inside include/laser_reader.h instead of include/laser_reader/laser_reader.h, then you could instead change the laser_reader.cpp to just #include “laser_reader.h” instead of #include “laser_reader/laser_reader.h”.
But the correct way is to just put the header file in the right place:
Hi, @ralves. Thank you very much for your help. It works now!
I tried both include/laser_reader.h and include/laser_reader/laser_reader.h before, but fortunately it works now.
By the way, I still keep the include guards as below:
#ifndef LASER_TURTLE_H #define LASER_TURTLE_H
should I replace them with LASER_READER_H. Sorry for my naive question. I am not very sure about this. Many thanks again!
I’m happy you finally managed to make it work, @super_leon.
Related to the #ifndef, it is good to keep the name of the header file, in this case, LASER_READER_H, just to avoid errors if you are also including in the program the laser_turtle.h
The #ifndef instructions means “if not defined”, so, “if not defined LASER_TURTLE_H, defined it by including all code until #endif”
At the end of the file you have the “#endif”.
The #ifndef, #define, #endif instructions are basically to include the header file only once.
If you remove the #ifndef and try to include the same file twice, you are going to have errors because the compiler identifies that you are trying to create classes that already exist, for example.
Please let me know if you have other related questions.
Hi, @ralves. Thank you so much for your detailed explanation! I am very sorry for my late response. I gained better understanding on how to set the headers. For now I think my questions have been solved perfectly. Many thanks again!