当前位置: 首页 > news >正文

下载安装mingw配置C++编译环境 及C环境

一.mingw相关操作

1.1.mingw官网下载

1.2.配置环境变量

1.2.1.复制路径配置新增系统变量

1.2.2.验证MinGW是否可以正常使用 

  • 环境变量配置:确保 E:/APP/VScode/mingw64/bin 已添加到系统 Path 变量中。
  • 编译器验证:在终端输入 g++ -v,若输出版本信息(如 g++ (x86_64-posix-seh-rev0) 8.1.0),则配置正确。

二.设置VSCode相关

2.1.下载安装好VSCode后先汉化

2.2.再C/C++安装相关插件

2.3.按需求补充插件

三.配置相关json(根据自身安装位置等配置)

3.1 C++相关的配置

3.1.1 c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "E:/APP/VScode/mingw64/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

3.1.2 launch.json

{
  "version": "0.2.0",
  "configurations": [
      {
          "name": "g++.exe - 生成和调试活动文件",
          "type": "cppdbg",
          "request": "launch",
          "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
          "args": [],
          "stopAtEntry": false,
          "cwd": "${workspaceFolder}",
          "environment": [],
          "externalConsole": false,
          "MIMode": "gdb",
          "miDebuggerPath": "E:/APP/VScode/mingw64/bin/gdb.exe",
          "setupCommands": [
              {
                  "description": "为 gdb 启用整齐打印",
                  "text": "-enable-pretty-printing",
                  "ignoreFailures": true
              },
              {
                  "description": "将反汇编风格设置为 Intel",
                  "text": "-gdb-set disassembly-flavor intel",
                  "ignoreFailures": true
              }
          ],
          "preLaunchTask": "build"
      }
  ]
}

3.1.3 tasks.json

{
  "version": "2.0.0",
  "tasks": [
      {
          "type": "cppbuild",
          "label": "build",
          "type": "shell",
          "command": "E:/APP/VScode/mingw64/bin/g++.exe",
          "args": [
              "-g",
              "${file}",
              "-o",
              "${fileDirname}/${fileBasenameNoExtension}"
          ],
          "group": {
              "kind": "build",
              "isDefault": true
          },
          "problemMatcher": [
              "$gcc"
          ]
      }
  ]
}

常见问题排查:
1.编译器路径错误:检查tasks.json和launch.json中的路径是否包含\bin\
2.中文路径问题:工程路径不要包含中文或特殊字符
3.旧进程占用:若修改后不生效,删除.vscode目录重新配置

3.1.4 settings.json

某些情况下可能需要修改settings.json。例如,设置IntelliSense模式或编译器路径。

需要确认用户是否需要在settings.json中添加特定设置,比如文件关联或插件配置。

{
    "files.associations": {
        "iostream": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "typeinfo": "cpp"
    }
}

3.2 C相关的配置

3.2.1 c_cpp_properties.json

{
  "configurations": [
      {
          "name": "Win32",
          "includePath": [
              "${workspaceFolder}/**",
              "E:/APP/VScode/mingw64/include",
              "E:/APP/VScode/mingw64/x86_64-w64-mingw32/include"
          ],
          "defines": [
              "_DEBUG",
              "UNICODE",
              "_UNICODE"
          ],
          "windowsSdkVersion": "10.0.19041.0",
          "compilerPath": "E:/APP/VScode/mingw64/bin/gcc.exe",
          "cStandard": "c11",
          "cppStandard": "c++17",
          "intelliSenseMode": "windows-gcc-x64"
      }
  ],
  "version": 4
}

3.2.2 launch.json

{
  "version": "0.2.0",
  "configurations": [
      {
          "name": "gcc.exe - 生成和调试活动文件",
          "type": "cppdbg",
          "request": "launch",
          "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
          "args": [],
          "stopAtEntry": false,
          "cwd": "${workspaceFolder}",
          "environment": [],
          "externalConsole": false,
          "MIMode": "gdb",
          "miDebuggerPath": "E:/APP/VScode/mingw64/bin/gdb.exe",
          "setupCommands": [
              {
                  "description": "为 gdb 启用整齐打印",
                  "text": "-enable-pretty-printing",
                  "ignoreFailures": true
              },
              {
                  "description": "将反汇编风格设置为 Intel",
                  "text": "-gdb-set disassembly-flavor intel",
                  "ignoreFailures": true
              }
          ],
          "preLaunchTask": "build"
      }
  ]
}

3.2.3 tasks.json

{
  "version": "2.0.0",
  "tasks": [
      {
          "label": "build",
          "type": "shell",
          "command": "E:/APP/VScode/mingw64/bin/gcc.exe",
          "args": [
              "-g",
              "${file}",
              "-o",
              "${fileDirname}/${fileBasenameNoExtension}"
          ],
          "group": {
              "kind": "build",
              "isDefault": true
          },
          "problemMatcher": [
              "$gcc"
          ]
      }
  ]
}

整理不易,诚望各位看官点赞 收藏 评论 予以支持,这将成为我持续更新的动力源泉。若您在阅览时存有异议或建议,敬请留言指正批评,让我们携手共同学习,共同进取,吾辈自当相互勉励!

相关文章:

  • 深入理解 YUV 颜色空间:从原理到 Android 视频渲染
  • 【前端】创建一个vue3+JavaScript项目流程
  • 指纹浏览器技术解析:如何实现多账号安全运营与隐私保护
  • 横扫SQL面试——时间序列分组与合并(会话划分)问题
  • 3.27-1 pymysql下载及使用
  • win10之mysql server 8.0.41安装
  • 从像素到二值化:OpenCV图像处理实战入门指南
  • 虫洞数观系列二 | Python+MySQL高效封装:为pandas数据分析铺路
  • Spring Boot中常用内嵌数据库(H2、HSQLDB、Derby)的对比,包含配置示例和关键差异总结
  • PyTorch量化进阶教程:第一章 PyTorch 基础
  • 如何分辨三极管的三个极
  • leetcode01背包问题(C++)
  • Splunk PDF 格式要求
  • (Kotlin)Android 高效底部导航方案:基于预定义 Menu 和 ViewPager2 的 Fragment 动态绑定实现
  • 【微服务架构】SpringCloud Alibaba(三):负载均衡 LoadBalance
  • 算法练习(队列)
  • 框架修改思路
  • Elasticsearch安全与权限控制指南
  • CoAP Shell 笔记
  • cocos 图片上传与下载
  • 有什么免费企业网站是做企业黄页的/百度seo搜索
  • wordpress论坛系统/微信搜索seo优化
  • 平度网站建设/怎么提升关键词的质量度
  • 网站seo设计方案案例/建站系统有哪些
  • 合肥外贸网站建设/推广赚钱的平台有哪些
  • wordpress 文章格式/谷歌seo是做什么的