Windows下C/C++编译器配置

安装mingw-x64

mingw-x64直接下载编译好的x86_64-win32-seh文件
在系统环境变量中直接添加该文件的bin目录

配置.vscode文件夹

.vscode\c_cpp_properties.json
路径部分可通过该指令查询: gcc -v -E -x c++ -

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                // 根据自己mingw的安装根目录找到include文件夹。更改下面这一行"D:/Mingw/mingw64/include**"
                "D:/SoftwareInstall/mingw64/include**",
                

                // 将查询结果直接粘进来
                "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
                "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "gcc-x64",
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "${workspaceRoot}",
                    // 以下7行需要修改
                    "D:/SoftwareInstall/mingw64/include**",
                    "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include",

                    // 将查询结果直接粘进来
                    "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                    "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                    "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                    "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                    "D:/SoftwareInstall/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed"
                ]
            }
        }
    ],
    "version": 4
}

.vscode\launch.json

{  
    "version": "0.2.0",  
    "configurations": [  
        {  
            "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示  
            "type": "cppdbg",       // 配置类型,这里只能为cppdbg  
            "request": "launch",    // 请求配置类型,可以为launch(启动)或attach(附加)  
            "program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径  
            "args": [],             // 程序调试时传递给程序的命令行参数,一般设为空即可  
            "stopAtEntry": false,   // 设为true时程序将暂停在程序入口处,一般设置为false  
            "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录  
            "environment": [],  
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台  
            "MIMode": "gdb",  

            // 这里的路径需要修改。改成自己的路径
            "miDebuggerPath": "D:/SoftwareInstall/mingw64/bin/gdb.exe",

            "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc  
            "setupCommands": [  
                {   
		            "description": "Enable pretty-printing for gdb",  
                    "text": "-enable-pretty-printing",  
                    "ignoreFailures": true  
                }  
            ]  
        }  
    ]  
}

.vscode\tasks.json

{
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe"
    ],
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "\\"
        ],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    },
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "D:\\SoftwareInstall\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}

你可能感兴趣的:(gcc,c++,windows,c语言)