ros2 编译时终端找不到#include包含路径
-
终端如下、
ywq@ywq-Dell-G15-5511:~/town_ws$ colcon build Starting >>> village_li Starting >>> village_wang --- stderr: village_wang /home/ywq/town_ws/village_wang/src/wang2.cpp:3:11: fatal error: std_msgs/std_msgs/msg/string.hpp: 没有那个文件或目录 3 | #include "std_msgs/std_msgs/msg/string.hpp" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. gmake[2]: *** [CMakeFiles/wang2_node.dir/build.make:76:CMakeFiles/wang2_node.dir/src/wang2.cpp.o] 错误 1 gmake[1]: *** [CMakeFiles/Makefile2:137:CMakeFiles/wang2_node.dir/all] 错误 2 gmake: *** [Makefile:146:all] 错误 2 --- Failed <<< village_wang [0.39s, exited with code 2]
原代码如下
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
求教为什么编译会找不到#include包含的"std_msgs/msg/string.hpp" 路径 -
@3194436830 后来问题解决了,需要在cmakelist.txt 文件下添加代码如下
ament_target_dependencies(wang2_node rclcpp std_msgs)
-
@3194436830 你添加这个代码的原因是什么?我也遇到了这个问题