标签:经验 launch pdb warning project log net entry esc
在重装了系统之后,之前配置的vscode调试运行C++环境没了很难受,今天再来配置一下,当初配置的时候折腾了好几天,今天把经验分享给大家。
其实vscode就是个附带了很多插件的记事本而已,所以它不能自己编译任何语言,配合插件使用才香,但是它所提供的C/C++插件仅支持语法检测而已,并不能编译运行,所以我们需要一个编译器,我这里选择mingw64
之前尝试过下载mingw64的安装包一键安装,但是下载太慢了,还是选择下载免安装版,解压一下配置好环境变量就行了
下载地址(免安装版):https://sourceforge.net/projects/mingw-w64/
解压过后配置环境变量:mingw安装目录下的bin文件夹
配置好之后在cmd中输入 gcc -v ,有gcc版本显示出来即为成功,失败的话可以仔细看看环境变量配置,或者去网上再下载一个mingw重新试一下
安装插件:C/C++和Code Runner,中文插件看自己需求下载
如果不需要调试,仅仅运行C/C++的话,到这里就可以了
调试需要配置launch.json和tasks.json两个文件
(这里两个选项其实随便选就行,后面直接ctrl+c v 就行)
{ "version": "0.2.0", "configurations": [ { "name": "C/C++", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:/Develop/mingw64/bin/gdb.exe", "preLaunchTask": "g++", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], }, ] }
{ "version": "2.0.0", "command": "g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${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 } }, "group": { "kind": "build", "isDefault": true } }
配置好之后就可以添加断点调试运行了~
感谢大佬指点:https://www.cnblogs.com/TAMING/p/8560253.html
从零开始 windows下配置vscode 编译/调试运行C++
标签:经验 launch pdb warning project log net entry esc
原文地址:https://www.cnblogs.com/xiezs/p/12496387.html