基础环境配置——VScode 调试C++程序

参考文章:

https://blog.csdn.net/bat67/article/details/76095813

最近从python要转向C++,只是简单的写一些C++程序,想在VScode上直接用起来,就需要自己手动装一些插件。写这篇博客也是因为安装的过程中遇到了一些不常见的错误,写下来跟大家分享一下。

1、安装cpptools插件

这个比较简单,直接再IDE上点一下,安装就行。

基础环境配置——VScode 调试C++程序

2、安装mingw-w64(解决“the file has been downloaded incorrectly”问题)

要自己手动安装一个for windows 的gcc。 

1、下载mingw-w64 installer

2、如果出现以下问题,尝试“以管理员身份运行”,如果还解决不了,就看步骤3

基础环境配置——VScode 调试C++程序

3、在https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/上下载相应的源码包:

基础环境配置——VScode 调试C++程序

4、找到(或者解压)bin目录,添加到path环境变量。

3、修改launch.json和添加tasks.jason文件

修改launch.json文件

"version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files\\mingw-w64\\bin\\gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },

添加tasks.json文件

{

    "version": "2.0.0",
    "command": "g++",
    "args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe"],    // 编译命令参数
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

 

上一篇:C语言I博客作业02


下一篇:【安利】Sublime Text 3配置C++