首先要安裝gdb和g++
sudo apt install -y gdb sudo apt install -y g++
先調試出錯之后,會出現.vscode的全局文件夾,兩個json的內容改成下面的,這樣工作文件夾里所有源碼都不用再設置兩個json了
launch.json
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現有屬性的描述。 // 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", //配置名稱,會在啟動配置的下拉菜單中顯示 "type": "cppdbg", //配置類型,只能為cppdbg "request": "launch", //請求類型,可以為launch或attach "program": "${workspaceFolder}/a.out", //將要調試的程序的路徑 "args": [], //調試時傳遞給程序的命令行參數 "stopAtEntry": false, //設為true程序會暫停在入口處 "cwd": "${workspaceFolder}", //調試程序時的工作目錄 "environment": [], //環境變量 "externalConsole": false, //調試時是否顯示控制台窗口 "MIMode": "gdb", //指定連接的調試器,可以為gdb或lldb "miDebuggerPath": "/usr/bin/gdb", //gdb路徑 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build" //調試開始前執行的任務,一般為編譯程序 } ] }
task.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "g++", "args": [ "${file}", "-o", "${workspaceRoot}/a.out" ], "group": { "kind": "build", "isDefault": true } } ] }