Windows10下使用Visual Studio Code编译C代码

第一步 安装MinGW

安装MinGW,并且配置MinGW变量使得在cmd下输入gcc -v能够打印出版本信息出来

第二步 安装Visual Studio Code并且安装相应的插件
第三步 编写相应的代码

hello.c
#include
int main(int argc, char const *argv[])
{
   printf("hello.word!");
   system("pause");
    return 0;
}


.vscode\launch.json
{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/hello.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "echo"
        }
    ]
}
.vscode\tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g",
                "hello.c",
                "-o",
                "hello.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
        }
    ]
}

其中tasks中写的就是编译命令上述表示在cmd执行gcc -g hello.c -o hello.exe,而launch则表示用于调试,并且调试工具是gdb,通过preLaunchTask指明了是哪个编译的tasks(通过tasks中的label指明)

发表回复

CAPTCHAis initialing...