VSCode配置MingW编译调试环境

本文详细介绍了如何在Windows系统中使用MingW和VSCode配置C++开发环境,包括下载安装MinGW、设置环境变量、编写tasks.json、c_cpp_properties.json和launch.json文件,以及调试过程中的配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.MingW简介

MinGW,即 Minimalist GNU For Windows。它是一些头文件和端口库的集合,该集合允许人们在没有第三方动态链接库的情况下使用 GCC(GNU Compiler C)产生 Windows32 程序。

实际上 MinGW 并不是一个 C/C++ 编译器,而是一套 GNU 工具集合。除开 GCC (GNU 编译器集合) 以外,MinGW 还包含有一些其他的 GNU 程序开发工具 (比如 gawk bison 等等)。

开发 MinGW 是为了那些不喜欢工作在 Linux(FreeBSD) 操作系统而留在 Windows 的人提供一套符合 GNU 的 GNU 工作环境。

2.准备工作

2.1 下载安装MingW

下载1.MingW   2.MingW2

 安装gcc之后,设置环境变量即可

3.配置编译调试 

3.1 tasks.json文件格式如下

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "C/C++: g++.exe 生成活动文件",
            "type": "cppbuild",
            "command": "C:/MinGW/bin/g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}/helow.exe"
            ],
            "options": {
                "cwd": "C:/MinGW/bin/"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "detail": "编译器: \"C:/MinGW/bin/g++.exe\""
        }
    ]
}

3.2 c_cpp_properties.json 文件如下:

{
  "configurations": [
      {
          "name": "Win32",
          "includePath": [
              "${workspaceRoot}",
              "C:/MinGW/include/**",
              "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
              "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32",
              "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward",
              "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
              "C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed",
              "C:/MinGW/mingw32/include"
          ],
          "defines": [
              "_DEBUG",
              "UNICODE",
              "_UNICODE"
          ],
          "compilerPath": "C:/MinGW/bin/g++.exe",
          "cStandard": "c11",
          "cppStandard": "c++11",
          "intelliSenseMode": "windows-gcc-x64",
          "browse": {
              "limitSymbolsToIncludedHeaders": true,
              "databaseFilename": "",
              "path": [
                  "${workspaceRoot}",
                  "C:/MinGW/include/**",
                  "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
                  "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32",
                  "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward",
                  "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
                  "C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed",
                  "C:/MinGW/mingw32/include"
              ]
          }
      }
  ],
  "version": 4
}

3.3 launch.json文件如下

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\helow.exe",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

4.参考文章

vscode安装+配置+使用+调试【保姆级教程】-CSDN博客

整理:Visual Studio Code (vscode) 配置C、C++环境/编写运行C、C++(主要Windows、简要Linux)_vscode配置c/c++环境-CSDN博客 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值