首先安装Mingw-w64

原本安装的是 MinGW-W64-install.exe 就是91k那个,安装参考http://c.biancheng.net/view/8077.html,但是因为墙还是什么的原因就等了好长时间安装好而且环境变量配置好后,cmd “gcc -v ”不是指定指令,就很崩溃。(但其实也不是没用,后面会说)

然后发现了个更简单的方法:

下载地址:https://sourceforge.net/projects/mingw-w64/files/

选择下面4个都可以

配置PATH环境变量,就是你解压后的文件路径,添加一个/bin的就行,我的是这个

E:\浏览器下载\x86_64-8.1.0-release-win32-seh-rt_v6-rev0\mingw64\bin

去cmd试下 “gcc -v ”有反应就是好了

后面两个要下的vscode插件我下好了,就先拿来试了一下这个方法,然后报错

stdio.h 未找到

好家伙,我去上面橙色路径mingw64/include的文件下一看就10个不到的.h文件,明显少货啊。

最后的解决方法是,从刚开始下载的MinGW-W64-install.exe下载好的/MinGW/include文件夹下的所有.h文件都复制过来

安装vscode插件

配置 3个.json文件

新建一个工程,然后建一个.c文件,随便写点代码,运行它,.vscode文件夹,文件夹下会生成launch.json文件,另外两个可以通过在该文件夹下新建  tasks.json、c_cpp_properties.json,目录结构如下图(settings.json没有也不用管

配置 launch.json文件(无脑复制)

{
    "version": "0.2.0",  
    "configurations": [  
        {  
            "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg",       // 配置类型,这里只能为cppdbg
            "request": "launch",    // 请求配置类型,可以为launch(启动)或attach(附加)  
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径  
            "args": [],             // 程序调试时传递给程序的命令行参数,一般设为空即可  
            "stopAtEntry": false,   // 设为true时程序将暂停在程序入口处,一般设置为false  
            "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录  
            "environment": [],  
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台  
            "MIMode": "gdb",  
            "miDebuggerPath": "D:\\English\\VScode\\mingw64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应  
            "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc  
            "setupCommands": [  
                {   
            "description": "Enable pretty-printing for gdb",  
                    "text": "-enable-pretty-printing",  
                    "ignoreFailures": true  
                }  
            ]  
        }  
    ]  
}

配置 task.json 文件(无脑复制)

{
    "version": "2.0.0",
    "command": "g++",
    "args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe"],    // 编译命令参数
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceFolder}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

配置c_cpp_properties.json文件(“compilePath”字段改成你所设的PATH值)

 
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

成功运行


所念皆星河