原因是在CMakeLists.txt中没有添加依赖:
ament_target_dependencies(wang2_pop_node rclcpp std_msgs)
如果问题还没有解决,则配置VSCode中的包含头文件
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/ros/humble/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}