mingw64下载安装
下载地址: https://sourceforge.net/projects/mingw-w64/files/
下滑找到:
其中x86_64指64位操作系统,i686指32位操作系统,win32是windows系统程序协议,posix是其他系统协议,seh仅支持64位操作系统,sjlj 32位64位都支持,dwarf仅支持32位。
下载好后解压到自定义路径(我是直接解压到D盘中的MinGW文件夹,并将解压后的文件重命名为mingw64),然后将mingw64的路径添加到系统变量。
完成后可在终端输入gcc,g++测试是否配置成功。
VS code配置C++环境
3个配置文件,c_cpp_properties.json,launch.json,tasks.json。
本人在launch.json中配置了两个启动,不需要debug时用(Windows) 启动(快一些),需要debug时用(gdb) 启动。编译好的程序都在中间文件夹temp中。
1, c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "D:\\MinGW\\mingw64\\bin\\g++",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
2, launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) 启动",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"preLaunchTask": "build",
"args": [
"/C",
"${workspaceFolder}\\temp\\${fileBasenameNoExtension}"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal"
},
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\temp\\${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\MinGW\\mingw64\\bin\\gdb.exe",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
3, tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}\\temp\\${fileBasenameNoExtension}",
]
}
]
}