前提: 本人电脑系统是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:本人已安装插件
ps:首先在磁盘上创建工作区,也就是创建文件夹并命名。本人已在E盘创建文件夹VScodeStudy
创建3个json文件,分别命名为:
launch.json tasks.json
c_cpp_properties.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
}