- 在主空间下新建文件夹,用vscode打开这个文件夹,写好一个cpp文件;
- 更改配置文件(launch.json):
点击左侧的Debug按钮,选择C++(GDB/LLDB),将自动生成launch.json文件;`
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
改后的launch.json文件如下:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
3.添加构建(编译、链接等)任务(tasks.json) 利用快捷键ctrl+shift+p打开命令行,输入Tasks: Run task,生成默认的tasks.json文件如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
}
]
}
这里的label为任务名,我们将”label"= “echo"改为”label”= “build”。 由于我们的指令是g++,这里将”command“=”echo Hello“改为”command“=”g++“。 然后添加g++的参数args。配置g++指令为:g++ -g main.cpp -std=c++11 -o main.out,则参数可设置为:
{
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"]
}
]
}
至此,完成了Ubuntu16.04 LTS下vscode的C/C++配置。 4.参考 1.https://blog.csdn.net/weixin_43374723/article/details/84064644?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.baidujs&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-4.baidujs 2.https://blog.csdn.net/weixin_41360517/article/details/102646390
|