vscode C/C++环境配置
最近使用vscode调试c文件出现了问题,总是cannot find the input file,经过一番努力,终于发现了问题所在
需要我们配置的json文件有两个:launch.json 、tasks.json
这里的逻辑是:
gcc用于生成可执行文件exe
gdb用于调试,调试前需要有可执行文件exe
调试的时候,如果没有可执行文件,就会通过preLaunchTask来生成exe;tasks.json用于配置生成exe的过程;因此tasks.json里的label值=preLaunchTask值
‘‘command’’+"args"组成了g++调试命令
g++ -g file.c -o file.exe
(g++命令可以自行了解)
在launch.json 里,"program"就是用gdb调试的可执行文件
附上launch.json 、tasks.json
launch.json
{
"version": "0.2.0",
"configurations":
[
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "build c/cpp", //gdb调试前用gcc生成二进制文件
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", //gdb调试的可执行文件
"args": [],
"stopAtEntry": false,//在程序的第一行设置Breakpoint
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",//gdb path 调试二进制文件
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build c/cpp",
"type": "shell",
"command": "g++",
"args": ["-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"],//g++ -g file.c/file.cpp -o file.exe
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
CSDN博客搬运 文章被收录于专栏
CSDN博客搬运