1.首先安装好gcc,在终端运行
sudo apt-get install g++
2. 首先创建一个文件夹,再对其进行编译,当然你要先安装cmake或者catkin_make,这就根据命令行的提示来就行。
3. 文件夹里面新建两个文件夹
修改里面的几个内容
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "compile",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
.task.json
{
"version": "2.0.0",
"tasks": [{
"label": "compile",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
4. 新建一个cpp文件,再在里面进行编写
5. 在c_cpp_properties.json里面添加路径,参考文章 Ubuntu上vscode中C++编译配置
6. 然后就可以进行运行啦