VScode配置C/C++编译环境

前提:  本人电脑系统是win7 64位,故本篇文章仅作参考。请根据本机系统自行下载对应的版本。


1、VScode下载安装

vscode下载地址:Download Visual Studio Code - Mac, Linux, Windows

官网下载

点击User Installer 64bit即可下载

点击“运行”
会弹出对话框,点击“确定”
出现安装界面,点击“下一步”
点击“下一步”
自定义选择安装目录
点击“下一步”
点击“下一步”
点击“安装”

2、MinGW安装

MinGWX64下载地址:MinGW-w64 - for 32 and 64 bit Windows -  Browse /mingw-w64/mingw-w64-release at SourceForge.net

版本说明:MinGW-64-bit - Qt Wiki

版本说明

如果没有跨平台编译需求,选win32;如果有的话,选posix,本人选择的是x86-64-posix-sjlj

离线安装包下载
下载完成

3、配置C/C++环境

(1)配置MinGW


配置环境变量
打开命令行

输入gcc -v

配置成功

(2)配置VScode

安装插件

ps:本人已安装插件

点击“Install”安装插件

ps:首先在磁盘上创建工作区,也就是创建文件夹并命名。本人已在E盘创建文件夹VScodeStudy

打开工作区
创建.vscode

创建3个json文件,分别命名为:

launch.json    tasks.json 

c_cpp_properties.json(可选择性创建)

创建json文件

launch.json内容

需要修改:注释标注的部分

注意:复制过来的地址的分隔符需要改为 ' \\ ' 或 ' / ',否则会报错

        {

            "name": "(gdb) Launch",

            "type": "cppdbg",

            "request": "launch",

            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",

            "args": [],

            "stopAtEntry": false,

            "cwd": "${workspaceFolder}",

            "environment": [],

            "externalConsole": true,

            "MIMode": "gdb",

            "miDebuggerPath": "E:/Mingw/mingw64/bin/gdb.exe", // 注意:修改gdb路径为你安装mingw的bin下的gdb.exe路径

            "preLaunchTask": "g++",

            "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",

    "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_cpp_properties.json内容

需要修改:“includePath”和"btowse"的"path"部分,两者内容保持一致

以下全部根据你的安装路径修改:

"E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",

"E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",

"E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",//

"E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include",//

"E:/Mingw/mingw64/include",

"E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed"

{

    "configurations": [

        {

            "name": "Win32",

            "intelliSenseMode": "clang-x64",

            "includePath": [

                "${workspaceFolder}",

                "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",//

                "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",//

                "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",//

                "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include",//

                "E:/Mingw/mingw64/include",//

                "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed"//

            ],

            "defines": [

                "_DEBUG",

                "UNICODE",

                "__GNUC__=7",

                "__cdecl=__attribute__((__cdecl__))"

            ],

            "browse": {

                "path": [

                    "${workspaceFolder}",

                    "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",//

                    "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",//

                    "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",//

                    "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include",//

                    "E:/Mingw/mingw64/include",//

                    "E:/Mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed"//

                ]

            },

            "limitSymbolsToIncludedHeaders": true,

            "databaseFilename": ""

        }

    ],

    "version": 4

}


4、开始编译

点击new file->创建main.cpp->点击右上角的三角形

创建cpp文件
运行成功
运行成功
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 参考:http://blog.csdn.net/c_duoduo/article/details/51615381...
    dpneko阅读 3,854评论 0 0
  • 最近因需要尝试编译了一次Vbox,官方论坛上只有32位环境的编译教程,所以这次在64位、特别是中文环境上遇到不少坑...
    MushiUta阅读 5,775评论 0 6
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,735评论 0 3
  • 此刻所记下的言论,也许以后看来,会显得十分幼稚,或者可笑,然而,记录的却是此时此刻真实的想法和感受。当我回头看时,...
    小鲨鱼2333阅读 170评论 2 1
  • 我们今天上美术课了!我画了个小汽车,它是一辆红色的车,有4个轮胎,1个窗户,还有一个车的身体,车身上有车门,车门上...
    余跃汐阅读 162评论 0 0