第一步:下载安装

下载MinGW-W64 GCC-8.1.0编译器(32和64版本都有)

MinGW-W64 GCC下载地址:https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/Personal Builds/mingw-builds/installer/mingw-w64-install.exe

vscode 多个lua文件 配置_vscode 多个lua文件 配置

或者这种方式,下载离线版本,推荐这个

离线下载地址:https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/安装选项为 x86_64-win32-seh

vscode 多个lua文件 配置_vscode 多个lua文件 配置_02

C:/Program Files (x86)/

安装目录选择,强烈建议这个目录下,省的后面还得自己改路径

C:/Program Files (x86)/mingw64/bin/

安装好后大概这个样子的目录

第二步:环境配置

打开你的mingw-w64安装目录,我是默认安装的在C:\Program Files (x86),里面的MinGW-W64就是安装的编译器了,将里面的bin文件夹加入路径,我的就是C:\Program Files (x86)\mingw64\bin,将这个加入路径即可。

路径加入方法:

vscode 多个lua文件 配置_vscode 多个lua文件 配置_03

  • 加入后,建议重启一下电脑

第三步 下载安装VSCode(已经装好了请跳到第四步)

  • vscode请到官网下载最新版(推荐管理权限64位版本)
  • 下载地址:https://code.visualstudio.com/#alt-downloads

vscode 多个lua文件 配置_vscodemac配置c++环境_04

第四步:安装VSCode cpp相关的插件

  • vscode设置中文环境教程http://www.chuancn.cn/post/将VSCode设置成中文语言环境
  • c++插件

vscode 多个lua文件 配置_vscode 多个lua文件 配置_05

  • -重启vscode软件

第五步:配置c++的.vscode文件

  • 在你写代码的地方新建文件夹C_code和里面新建一个文件夹.vscode

vscode 多个lua文件 配置_vscode 多个lua文件 配置_06

在vscode中,打开文件夹C_code文件夹,也就是这个


vscode 多个lua文件 配置_vscode http post_07

vscode 多个lua文件 配置_vscode http post_08

然后在.vscode文件夹里面创建如上图所示的四个文件,文件名如下


c_cpp_properties.jsonlaunch.jsontasks.json

  • 请根据安装的位置来修改文件路径(如果跟我一样可以不要修改)
  • launch.json
{    "version": "0.2.0",    "configurations": [        {            "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示            "type": "cppdbg", // 配置类型,这里只能为cppdbg            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径            "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false            "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录 workspaceRoot已被弃用,现改为workspaceFolder            "environment": [],            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台            "MIMode": "gdb",            "miDebuggerPath": "C:/Program Files (x86)/mingw64/bin/gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应            "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc            "setupCommands": [                {                    "description": "Enable pretty-printing for gdb",                    "text": "-enable-pretty-printing",                    "ignoreFailures": false                }            ]        }    ]}

  "miDebuggerPath": "C:/Program Files (x86)/mingw64/bin/gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应上面的这一行代码,必须跟自己安装的位置一模一样,后面涉及到路径的同理

tasks.json

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

c_cpp_properties.json

{    "configurations": [        {            "name": "Win32",            "includePath": [                "${workspaceRoot}",                "C:/Program Files (x86)/mingw64/include/**",                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",                "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"            ],            "defines": [                "_DEBUG",                "UNICODE",                "__GNUC__=6",                "__cdecl=__attribute__((__cdecl__))"            ],            "intelliSenseMode": "msvc-x64",            "browse": {                "limitSymbolsToIncludedHeaders": true,                "databaseFilename": "",                "path": [                    "${workspaceRoot}",                    "C:/Program Files (x86)/mingw64/include/**",                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",                    "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"                ]            }        }    ],    "version": 4}

这里也是,目录一定要是自己的mingw64

vscode 多个lua文件 配置_vscodemac配置c++环境_09

第六步:完成调试

打开文件夹后,新建test.cpp(随便建,或者main.cpp)进行输入代码测试: 

#include using namespace std; int main(){    cout << "hello" << endl;    return 0;}

按F5启动调试~

vscode 多个lua文件 配置_vscode http post_10

然后会发现有一个黑框一闪而过,然后终端显示“终端将被任务重用,按任意键关闭”,说明大家的配置没问题啊评论区有这个问题的童鞋们!只是vscode不是自己在程序末尾停止而已啦,和IDE不一样。

可以在最后加一个断点,或者getchar(),或者system("pause");  或者int pause;cin>>pause; 看个人喜好了,个人感觉最后在return 0;处打一个断点比较好。然后程序就会在最后停住了。

vscode 多个lua文件 配置_vscodemac配置c++环境_11

一劳永逸:因为VS需要为每一个文件夹做单独配置,所以建议把.vscode文件夹放到你常用的文件夹的顶层,这样就不用重复配置了。
不用每个新cpp文件就要一套配置。这些配置在你配置好的文件夹内的所有子文件夹和文件都能使用。