1.下载mingw64源码:
下载链接:https://sourceforge.net/projects/mingw-w64/
选中版本下载 x86_64-posix-seh 解压后将/bin下路径加入环境变量,个人环境变量和系统环境变量。
cmd中输入gcc -v查看是否安装好了mingw64
2.官网下载安装vscode
3.配置vscode安装环境
安装如下组件
3.1 配置launch.json
vscode界面点击 Debug>>Open Configurations>>c++(GDB/LLDB)会自动新建一个launch.json文件,修改为如下内容
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:/mingW64/mingw64/bin/gdb.exe", //gdb 的路径
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
"preLaunchTask":"build" //名字对应编译的task
}
]
}
3.2 配置task.json
生成task.json文件,修改文件如下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g", //生成调试信息
"-Wall", //开启额外警告
"-static-libgcc", //静态链接
"-std=c++11" //c++新特性版本
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"echo":true,
"reveal": "always", //在终端显示信息的策略,可以为always,silent,never
"focus":false, //设置为true可使执行task时焦点聚集在终端.对c/c++意义不大
"panel": "shared" //不同的文件的编译信息共享一个终端面板
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$gcc"
}
]
}
3.3配置c_cpp_properties.json
ctrl + shift + p -》 “C/Cpp: Edit configurations” ,生成c_cpp_properties.json 文件,修改成如下内容:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
"D:/mingW64/mingw64/x86_64-w64-mingw32/include",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed",
"D:/mingW64/mingw64/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/mingW64/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
重启vscode就可以进行c/c++代码编写调试了
参考链接:https://www.cnblogs.com/ghjnwk/p/9806677.html