Install the following extensions as detailed here
- C/C++
- CMake
- ROS
- Clang Format
bash sudo apt-get install clang-formatAlso, go to the settings by typing ‘Ctrl + ,’ and search for ‘editor.formatOnSave’ and set it to true. Otherwise the files need to be formatted with manual commands. - vscode-icons
- If you haven't already, navigate to File > Open Folder and open the top-level catkin workspace or a ROS package.
- Navigate to File > Save Workspace As... and save (this is just to generate the
.vscodefolder and can be removed later). - Expand the
.vscodefolder and openc_cpp_properties.jsonand paste the following after thebrowseelement, but before theincludePathelement. Be wary of missing commas.
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "c++14",
"intelliSenseMode": "gcc-x64",- The file should look similar to this (except auto-populated with the packages in your workspace)
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": false
},
"name": "ROS",
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "c++14",
"intelliSenseMode": "gcc-x64",
"includePath": [
"~/pcl_ws/devel/include/**",
"/opt/ros/melodic/include/**",
"/opt/ros/melodic/include/**/**",
"/opt/ros/melodic/share/fetch_gazebo/include/**",
"/opt/ros/melodic/share/julius/include/**",
"~/catkin_ws/src/pkg2/include/**",
"~/catkin_ws/src/pkg1/include/**",
"/usr/include/**"/**
]
}
],
"version": 4
}- Press Ctrl + N to open a new file, paste the code below. Then Ctrl + S to save the file, naming it
tasks.json. Be sure to save it in the same.vscodefolder alongside the previousc_cpp_properties.json
{
"version": "2.0.0",
"tasks": [
{
"type": "catkin",
"args": [
"build",
"--force-cmake",
"--continue"
],
"problemMatcher": [
"$catkin-gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"label": "catkin: build all",
"options": {
"cwd": "${fileDirname}"
}
},
{
"label": "example_launch",
"type": "shell",
"command": "roslaunch example_pkg example.launch",
"problemMatcher": [],
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "catkin clean",
"type": "shell",
"command": "catkin clean --all-profiles"
}
]
}- Your
.vscodefolder should now look similar to this
.vscode/
├── c_cpp_properties.json
├── tasks.json
└── workspace.code-workspace
- Confirm the tasks were specified by using Ctrl + Shift + B to run the
catkin buildtask that was just made
Ref: https://samarth-robo.github.io/blog/2020/12/03/vscode_ros.html ms-iot/vscode-ros#114 (comment)