vscode C++ 程序 windows

vscode 1.42.1 OS: windows 7 x64

1. vscode, cpp extension

本文直接跳過 vscode 安裝, Cpp tools 安裝

file

2. MinGw 安裝及配置

下載MinGW - Minimalist GNU for Windows file

安裝過程 file

安裝所需依賴環境 file

3. 配置環境變量

file

4. 調試

配置 launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,  // 這裏要改爲true
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++"
        }
    ]
}

配置task.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "g++",
            "type": "shell",
            "command": "D:\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],

            "options": {
                "cwd": "D:\\MinGW\\bin"
            },

            "problemMatcher": [
                "$gcc"
            ],

            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "new",
                "showReuseMessage": true,  //這裏shared表示共享,改成new之後每個進程創建新的端口
                "clear": false
            }
        }
    ]
}

最後結果

file

參考

  1. 整理:Visual Studio Code (vscode) 配置C、C++環境/編寫運行C、C++(主要Windows、簡要Linux)
  2. vscode 基本知識以及如何配置 C++ 環境
  3. 關於VScode報錯“終端將被任務重用,按任意鍵關閉”的解決方案
  4. VSCode 代碼調試器
  5. windows 10上使用vscode編譯運行和調試C/C++
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章