最近,我尝试用
ROS
配置 VS Code
。
我习惯了与
Clion
一起工作,所以我对 VS Code
还比较陌生。
我创建了一个非常简单的
main.cpp
,其中包括 ROS
标题:
#include <iostream>
#include <vector>
#include <string>
#include <ros/ros.h>
using namespace std;
int main(int &argc, char **argv)
{
ros::init(argc, argv, "example");
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
然后,我遇到了这个错误
ros/ros.h: No such file or directory
根据网上的结果,我尝试使用ROS扩展(v0.9.2)的
c_cpp_properties.json
将相关路径添加到ROS: Update C++ Properties
。
另外,我对
tasks.json
和settings.json
进行了更改,但这个错误仍然存在。
我已经尝试过
catkin build
,一切正常。
我是否错过了一些其他配置?
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "catkin build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=1",
"problemMatcher": [
"$catkin-gcc"
],
"label": "catkin_build"
},
{
"type": "catkin",
"args": [
"clean",
"--yes"
],
"problemMatcher": [
"$catkin-gcc"
],
"label": "catkin_clean"
},
{
"command": "${workspaceFolder}/merge_compile_commands.sh",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"label": "catkin: build",
"problemMatcher": [],
"dependsOn": [
"catkin_build"
]
},
{
"command": "rm ${workspaceFolder}/compile_commands.json",
"type": "shell",
"problemMatcher": [],
"group": "build",
"label": "catkin: clean",
"dependsOn": [
"catkin_clean"
]
},
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
设置.json:
{
"python.autoComplete.extraPaths": [
"/home/xzc/ws_moveit/devel/lib/python3/dist-packages",
"/opt/ros/noetic/lib/python3/dist-packages"
],
"python.analysis.extraPaths": [
"/home/xzc/ws_moveit/devel/lib/python3/dist-packages",
"/opt/ros/noetic/lib/python3/dist-packages"
],
"ros.rosSetupScript": "/opt/ros/noetic/setup.bash",
"ros.distro": "noetic",
"files.associations": {
"string": "cpp"
},
"cmake.sourceDirectory": "/home/xzc/vs_catkin_ws/src/hello_vs_code"
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file"
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"browse": {
"databaseFilename": "${default}",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
"/opt/ros/noetic/include",
"/home/xzc/vs_catkin_ws/src/hello_vs_code/include/**",
"/usr/include/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++14",
"compileCommands": "${workspaceFolder}/compile_commands.json"
}
],
"version": 4
}