VScode 配置c++環境


參考

https://code.visualstudio.com/docs/cpp/config-mingw

https://zhuanlan.zhihu.com/p/77645306 主要

 

官網給出的配置過程稍微復雜一些

以下內容參考  知乎 唐銘   https://zhuanlan.zhihu.com/p/77645306   

 

1.安裝vscode

官網下載安裝即可

2.安裝mingw64

建議安裝離線版

https://sourceforge.net/projects/mingw-w64/

安裝好后添加環境變量

 

 檢測

 

 3.安裝插件

安裝必要的插件,打開vscode,點擊左面豎排第五個按鈕,搜索並安裝

  • C/C++
  • Code Runner

 

4.配置文件

新建文件夾(工作區)project

新建文件夾.vscode

新建文件launch.json,tasks.json

##launch.json 

注意修改mingw路徑
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:/mingw64/mingw64/bin/gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        },
    ]
}

 

##tasks.json 

{
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}.exe"
    ],
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "${workspaceRoot}"
        ],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    },
    "group": {
        "kind": "build",
        "isDefault": true
    }
}

 

5.具體調試

 

內容見https://zhuanlan.zhihu.com/p/77645306

 


免責聲明!

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



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