【安利】VScode配置C++开发环境

写在前面

我看很多人都在用vscode,网上教程很多,咱也不能落下对吧。。

安装MinGW-w64

解压下载后的mingw-w64.7z,打开mingw-w64-install.exe,点击Next,然后等待一会儿就会出现一个框框,里面有5个下拉列表,从上到下依次选择

第一个为Version,选择最新版即可
第二个为Architecture,选择x86_64
第三个为Threads,选择poxiv
第四个为Exception,选择seh
第五个为Build revision,选择0

然后就一路点击Next知道开始安装,等进度条加载完就安装成功了(可能有点久,但毕竟是微软使用的MinGW相对靠谱点,等不及的可以网上百度MinGW的安装方法)

在系统环境变量里加入:(环境变量在哪不用我说吧)

变量名(没有就新建)变量值
PathC:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin

安装VScode

下载安装应该不用我讲吧。然后打开文件夹,注意,一定要打开才能编译运行、调试。

在下载扩展界面下载以下几个必备插件:C/C++C++ Intellisense(再推荐俩美化插件,要不要下由你:Atom One Dark ThemeMaterial Icon Theme

在打开的文件夹里面创建一个名叫.vscode的文件夹,再在里面添加launch.jsontasks.json两个文件,分别往俩文件里输入以下内容:

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run C/C++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "build & run file"
        },
        {
            "name": "Debug C/C++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "build & debug file"
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build & debug file",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "-o",
                "${fileBasenameNoExtension}",
                "${file}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "build & run file",
            "type": "shell",
            "command": "g++",
            "args": [
                "-o",
                "${fileBasenameNoExtension}",
                "${file}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

然后就可以按f5编译运行啦,在左侧栏的小虫子里面可以修改调试方式,选Run是运行,选Debug是调试。

撒花完结

相关推荐