当前位置:网站首页>VSCode关于C语言的3个配置文件

VSCode关于C语言的3个配置文件

2022-07-07 15:40:00 Larry Chow

在cmd.exe中输入如下命令:
gcc -v -E -x c++ -

当用vscode打开文件夹,会自动创建.vscode文件夹,在该文件夹中,创建3个配置文件,分别是c_cpp_properties.json、launch.json、tasks.json。

将红框中的信息在配置文件中,做替换。

在c_cpp_properties.json中

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "D:/programFiles/MinGW/include/**",
                "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include/c++",
                "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include/c++/mingw32",
                "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include/c++/backward",
                "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include",
                "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/../../../../include",
                "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include-fixed"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "${workspaceRoot}",
                    "D:/programFiles/MinGW/include/**",
                    "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include/c++",
                    "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include/c++/mingw32",
                    "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include/c++/backward",
                    "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include",
                    "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/../../../../include",
                    "D:/programFiles/MinGW/bin/../lib/gcc/mingw32/6.3.0/include-fixed"
                ]
            }
        }
    ],
    "version": 4
}

在launch.json中

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "cmd",
            "preLaunchTask": "echo",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "&",
                "echo.",
                "&",
                "pause"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole":true
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",// 自己电脑的gdb
            "preLaunchTask": "echo",//这里和task.json的label相对应
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
 
        }
    ]
}

在tasks.json中:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g", 
                "${file}", 
                "-o", 
                "${fileBasenameNoExtension}.exe",
                "-fexec-charset=GBK"//解决中文乱码
            ]
        }
    ],
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared", 
        "showReuseMessage": true,
        "clear": false
    }
}

原网站

版权声明
本文为[Larry Chow]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41704436/article/details/125650206