vscode調試C程序


1、程序路徑不能有中文,因為MinGW不支持

2、選擇一個文件夾當作工作區,並且在該文件夾下創建./vscode文件夾,並在該文件夾下創建兩個json文件

  launch.json

  

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,  //彈出黑框使用true,不彈出使用false
            "MIMode": "gdb",
            "miDebuggerPath": "D:/MinGW/bin/gdb.exe",  //選擇gbd.exe的絕對路徑
            "preLaunchTask": "compile",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        },
    ]
}

 

  tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "compile",
            "command": "gcc",  //c文件就用gcc,cpp文件就用g++
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

題外話:

如果想讓vscode運行向dev-c++一樣出現黑框的話,需要安裝C/C++ Compile Run插件

除此之外,需要將設置-擴展-Compile Run configuration中找到如下選項進行勾選,使用F6運行

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM