vscode编译调试linux c/c++
程序员文章站
2022-03-06 08:08:50
...
1.远程打开linux服务器上的开发工程文件夹(具体工程不进行介绍了),如:
/home/user/my_pro
2.在产生的 .vscode 文件夹下放置 launch.json,tasks.json 配置文件,内容如下:
launch.json:
{
"version": "0.2.0",
"configurations": [
{
// 工程项目名称
"name": "test1",
"type": "cppdbg",
"request": "launch",
// gdb启动调试的目标生成文件
"program": "${workspaceFolder}/test1",
// 目标文件启动参数
"args": [],
"stopAtEntry": false,
// 当前工作路径
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
// launch启动调试前依赖的 tasks.json 中的task配置,一般是用于调试前的代码编译
"preLaunchTask": "build-project"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
// task名称,对应launch.json里面 preLaunchTask 配置
"label": "build-project",
"type": "shell",
// 编译命令(如果使用make、cmake等等编译方式编译,则设为相应的命令)
"command": "g++",
// 编译参数
"args": [
"-std=c++11",
"-g",
"main.cpp",
"-pthread",
"-o",
"test1"
]
}
]
}
3.点击左侧运行调试按钮开始编译调试