分享

vscode C++ 程序 windows

 丹枫无迹 2022-07-13 发布于北京

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++
    公号 [ 同叔练级之路 ]
    Certainty of death. Small chance of success.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多