新手搭建C编程环境(使用VScode+Windows环境)

作者在 2023-03-23 16:02:53 发布以下内容
1、下载VScode
Visual Studio Code - Code Editing. Redefined
2、安装完成后,参考VScode的文档进行配置:
开始使用 Visual Studio Code 中的 C++ 和 Mingw-w64
PS:需要汉化在搜索栏搜索Chinese,安装、重启即可

3、通过MSYS2获取最新版本的Mingw-w64,它提供了GCC,Mingw-w64和其他有用的C++工具和库的最新本机版本。您可以从 MSYS2 页面下载最新的安装程序,也可以使用此链接到安装程序。
4、添加完环境变量后,就可以编写C语言并进行调试了。要注意第一次调试需要配置两个文件(针对C语言、C++本人暂未涉猎)分别是launch.json、tasks.json,我用的是最简单的配置(能用就行),配置好,就可以使用了。
launch.json
{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "C/C++: g++.exe build and debug active file",  //名称
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "D:\\msys64\\mingw64\\bin\\gdb.exe",  //可以修改,指向你自己安装的mingw64\\bin位置
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "C/C++: g++.exe build active file"
      }
    ]
  }
tasks.json
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\\msys64\\mingw64\\bin\\gcc.exe",  //可以修改,指向你自己安装的mingw64\\bin位置
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\msys64\\mingw64\\bin" //可以修改,指向你自己安装的mingw64\\bin位置
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        },
    ],
    "version": "2.0.0"
}
默认分类 | 阅读 2092 次
文章评论,共1条
牛咕噜
2023-04-21 07:45
1
好帖,解决了问题
游客请输入验证码
文章归档