How to fix ROS fatal error: ros/console.h: No such file or directory
Problem
You are trying to colcon build
a ROS library or project but you see the following error log:
In file included from /home/user/message_logger/build/message_logger/include/message_logger/log/log_messages_backend_config.hpp:61,
from /home/user/message_logger/include/message_logger/log/log_messages_backend.hpp:46,
from /home/user/message_logger/include/message_logger/log/log_messages.hpp:44,
from /home/user/message_logger/include/message_logger/message_logger.hpp:43,
from /home/user/message_logger/src/demo.cpp:6:
/home/user/message_logger/include/message_logger/log/log_messages_ros.hpp:43:10: fatal error: ros/console.h: No such file or directory
43 | #include <ros/console.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/demo.dir/build.make:76: CMakeFiles/demo.dir/src/demo.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:185: CMakeFiles/demo.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
gmake: *** [Makefile:146: all] Error 2
Solution
Currently, the ros-console
package is not available in the official ROS2 apt repository at the time of writing this.
Therefore, I recommend you to clone the repo, build it using colcon
and then source install/setup.bash
before building your package.
git clone https://github.com/ros/rosconsole
cd rosconsole
colcon build
source install/setup.bash
After that (in the same shell), build your other package using colcon build
again.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow