Windows11配置MSYS2+vscode+cpp+cmake环境

1 安装vscode和c++扩展


2 安装MSYS2

2.1 安装mingw工具链(内含g++等工具)

MSYS2 MSYS窗口运行

bash 复制代码
 pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain

2.2 添加环境变量

  • 在开始菜单搜索编辑系统环境变量
  • 编辑Path,将msys64\ucrt64\bin的绝对路径添加进去

2.3 验证安装

Win+R并输入cmd打开终端,输入以下内容进行验证

bash 复制代码
gcc --version
g++ --version
gdb --version

2.4 安装cmake

MSYS2 MSYS窗口运行

bash 复制代码
pacman -S mingw-w64-ucrt-x86_64-cmake
  • 验证安装:
    Win+R并输入cmd打开终端,输入以下内容进行验证

首先检查路径对不对(一般是ucrt64\bin\cmake.exe)

bash 复制代码
where cmake

然后

bash 复制代码
cmake --version

3 vscode配置文件

c_cpp_properties.json

bash 复制代码
{
    "configurations": [
        {
            "name": "GCC",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "compilerPath": "C:\\Users\\msys64\\ucrt64\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

launch.json

bash 复制代码
{
    "version": "2.0.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": "C:\\Users\\msys64\\ucrt64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}

tasks.json

bash 复制代码
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\Users\\msys64\\ucrt64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always", // 彩色输出编译错误信息
                "-g",
                "${file}",
                "${workspaceFolder}/include/*.cpp",
                "-I",
                "${workspaceFolder}/include",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
相关推荐
权在码代码2 小时前
CodeX CLI安装+MCP适配与VSCode部署(Win)
ide·vscode·codex·mcp·aicoding
小蕾Java2 小时前
IntelliJ IDEA 2025:最新使用图文教程!
java·ide·intellij-idea
旷野说3 小时前
Android Studio Narwhal 3 特性
android·ide·android studio
加油_Yeah5 小时前
cursor使用之没有正常的编辑器中的运行箭头
编辑器·cursor
HBR666_5 小时前
AI编辑器(二) ---调用模型的fim功能
前端·ai·编辑器·fim·tiptap
馨谙13 小时前
vim保姆级使用,操作详解,快捷键大全总结
linux·编辑器·vim
省四收割者14 小时前
Go语言入门(20)-nil
开发语言·vscode·golang
安卓AndroidQ19 小时前
Android Studio 代码混淆核心解释
android·ide·android studio
就叫飞六吧19 小时前
Android studio -kt构建一个app
android·ide·android studio