问题描述
在配置VSCode进行ROS开发时,可能会出现智能提示无法正常工作的情况。这通常表现为:
- 代码补全功能失效
- 错误提示不准确
- 无法跳转到函数或变量的定义
我的解决办法
第一步:确认vscode的c_cpp_properties.json
我使用clang进行提示,确认有下面的配置
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
我的完整文件如下,供参考
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/ros/noetic/include/**",
"/usr/include/**",
"/usr/lib/**",
"/usr/local/include",
"${workspaceFolder}/devel/include",
"${workspaceFolder}/src/BehaviorTreeCPP/include",
"${workspaceFolder}/src/robot_manager/include",
"${workspaceFolder}/src/hric_global_planner/global_planner/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
第二步 catkin生成compile_commands.json文件
执行命令
cakin_make -DCMAKE_EXPORT_COMPILE_COMMANDS=1
之后就可以看到vscode自动补全了