美文网首页
Windows + VS Code + MinGW

Windows + VS Code + MinGW

作者: cybersword | 来源:发表于2018-05-02 19:05 被阅读0次

    本文介绍Windows上搭建C开发编译环境

    参考帖子

    知乎

    下载链接

    MinGW-W64 GCC-7.3.0

    MinGW安装

    优先尝试mingw-w64-install.exe
    如果网络错误,则直接下载上面的压缩包x86_64-win32-sjlj,解压到指定目录即可,如在D盘创建文件夹,并解压,得到目录:D:\dev\mingw64
    我的电脑、右键属性、系统属性、环境变量、系统变量、Path中增加一行D:\dev\mingw64\bin
    如下图

    image.png

    Win + X组合键管理员身份打开命令行输入gcc回车,提示缺少输入文件说明安装成功

    VS Code 配置

    在D盘创建code文件夹,在code文件夹中创建c文件夹
    打开VS Code,文件打开文件夹,选择D:\code\c
    此时VS Code会在D:\code\c目录下创建一个隐藏文件夹.vscode,里面会有一个文件D:\code\c\.vscode\c_cpp_properties.json

    修改configurations数组里面"name": "Win32"下的includePath
    增加以下路径,即可在VS Code里面查看include的文件内容

    "D:/dev/mingw64/include",
    "D:/dev/mingw64/x86_64-w64-mingw32/include",
    

    注意最后一行的结尾没有逗号

    {
        "configurations": [
            {
                "name": "Mac",
                "includePath": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceFolder}"
                ],
                "defines": [],
                "intelliSenseMode": "clang-x64",
                "browse": {
                    "path": [
                        "/usr/include",
                        "/usr/local/include",
                        "${workspaceFolder}"
                    ],
                    "limitSymbolsToIncludedHeaders": true,
                    "databaseFilename": ""
                },
                "macFrameworkPath": [
                    "/System/Library/Frameworks",
                    "/Library/Frameworks"
                ]
            },
            {
                "name": "Linux",
                "includePath": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceFolder}"
                ],
                "defines": [],
                "intelliSenseMode": "clang-x64",
                "browse": {
                    "path": [
                        "/usr/include",
                        "/usr/local/include",
                        "${workspaceFolder}"
                    ],
                    "limitSymbolsToIncludedHeaders": true,
                    "databaseFilename": ""
                }
            },
            {
                "name": "Win32",
                "includePath": [
                    "${workspaceFolder}",
                    "D:/dev/mingw64/include",
                    "D:/dev/mingw64/x86_64-w64-mingw32/include",
                    "D:/dev/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
                    "D:/dev/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/ssp",
                    "D:/dev/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/tr1"
                ],
                "defines": [
                    "_DEBUG",
                    "UNICODE",
                    "_UNICODE"
                ],
                "intelliSenseMode": "msvc-x64",
                "browse": {
                    "path": [
                        "${workspaceFolder}",
                        "D:/dev/mingw64/include",
                        "D:/dev/mingw64/x86_64-w64-mingw32/include",
                        "D:/dev/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
                        "D:/dev/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/ssp",
                        "D:/dev/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/tr1"
                    ],
                    "limitSymbolsToIncludedHeaders": true,
                    "databaseFilename": ""
                },
                "cStandard": "c11",
                "cppStandard": "c++17"
            }
        ],
        "version": 3
    }
    

    VS Code 中 Ctrl + ` 组合键打开终端

    编译
    PS D:\code\c> gcc .\list.c -o list.exe
    

    -o 指定输出的可执行文件名

    执行
    PS D:\code\c> .\list.exe
    
    image.png

    相关文章

      网友评论

          本文标题:Windows + VS Code + MinGW

          本文链接:https://www.haomeiwen.com/subject/rbncrftx.html