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"
}
相关推荐
zfj3213 小时前
vscode是js开发的,为什么能支持golang java等各种语言开发
javascript·vscode·golang
Lv11770085 小时前
Visual Studio中的字典
ide·笔记·c#·visual studio
Alsn865 小时前
24.idea专业版安装+maven、tomcat安装并部署到idea
java·ide·intellij-idea
有梦想的鱼6 小时前
vscode letax编译中英文论文(傻瓜式、一分钟)
ide·vscode·编辑器
qq_214782617 小时前
GWalkR,部分替代Tableau!
ide·python·jupyter
jiayong2310 小时前
IntelliJ IDEA 使用指南
java·ide·intellij-idea
前端无涯10 小时前
Qoder的使用
前端·ide·ai·qoder
爱埋珊瑚海~~10 小时前
Android Studio模拟器一直加载中
android·ide·android studio
编程大师哥10 小时前
Android Studio 2025 从性能优化到开发体验下载安装教程安装包
android·ide·android studio
Lv117700810 小时前
Visual Studio 中的字符串
ide·笔记·c#·visual studio