ROS2 编译错误和警告

1. 删除自定义包后出现警告

WARNING:colcon.colcon_ros.prefix_path.ament:The path xxx AMENT_PREFIX_PATH doesn’t exist
WARNING:colcon.colcon_ros.prefix_path.catkin:The path xxx CMAKE_PREFIX_PATH doesn’t exist

ROS2 删除自定义包后 编译警告
在终端内:使用命令列出编译路径

printenv  AMENT_PREFIX_PATH CMAKE_PREFIX_PATH

然后根据自己删除的包删除对应的路径后再赋值回去

export AMENT_PREFIX_PATH=xxx
export CMAKE_PREFIX_PATH=xxx

2. 编译通过,运行报错 ImportError

ImportError: /home/fly/ros2_ws/install/ssd_msg/lib/libssd_msg__python.so: undefined symbol: std_msgs__msg__header__convert_from_py

这个错误是由于msg里面带有std_msgs, 而遍历环境没有配置std_msgs依赖导致加载错误
Can.msg如下

std_msgs/Header header

uint32 id
uint8 len
byte[8] data

修改CMakeList.txt,添加对应的依赖

find_package(std_msgs REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Can.msg"
DEPENDENCIES std_msgs

3. 编译通过,运行报错 Assertion

ssd_msg__msg__can__convert_from_py: Assertion `PyBytes_Check(item)’ failed.
这个错误是由于类型转换不对应导致的

因为我这个是msg同时在python和c++中都有被导入, 其中byte[8] data在python中和c++中类型转换不同,最终修改了类型使用uint8[8] data

msgs只是简单的文本文件,每行有一个字段类型和字段名称。可以使用的字段类型是:

  1. int8, int16, int32, int64 (plus uint*) f
  2. loat32, float64
  3. string
  4. other msg files
  5. variable-length array[], fixed-length array[C], bounded-length array[<=C]

4. 删除自定义的msg后报错

CMake Error at /opt/ros/dashing/share/rosidl_cmake/cmake/rosidl_target_interfaces.cmake:40 (message):
rosidl_target_interfaces() the second argument ‘can_pkg’ must be a valid

删除msg后,因为只屏蔽了下面的中间加载部分,没有屏蔽第三部分导致编译出错,可以删除一下三部分,至少要删除后两个,package.xml中的相关项也可以删除

#find_package(rosidl_default_generators REQUIRED)

#rosidl_generate_interfaces(${PROJECT_NAME}
	#"msg/Can.msg"
	#"msg/Object.msg"
	#"msg/Array.msg"
	#"msg/Control.msg"
	#"msg/Status.msg"
	#DEPENDENCIES builtin_interfaces std_msgs 
#)

#rosidl_target_interfaces(radar_parsing_node ${PROJECT_NAME} "rosidl_typesupport_cpp")

你可能感兴趣的:(ROS2 编译错误和警告)