报错:g++.exe: error: unrecognized command line option '--interpreter=mi 原因
在官网 https://sourceforge.net/projects/mingw-w64/下载安装mingw-w64。
下载完成之后,将刚才下载目录下的bin文件夹目录配置到环境变量里
CMD窗口输入gcc -v不报错就证明配置成功
VSCode中搜索 C/C++ 、 Code Runner 扩展进行安装
开始配置C/C++环境:
1. VSCode中 Ctrl+Shift+P 调出命令面板,输入C/C++,选择Edit Configurations(UI)进入配置。
配置一,找到编译器路径:配置你刚才的安装路径下的g++.exe,例如D:/mingw-w64/bin/g++.exe。配置二,找到IntelliSense模式:gcc-x64。查找g++.exe等路径:打开CMD,输入where xxx。例如where g++.exe 。
按快捷键 Ctrl+Shift+P调出命令面板,输入tasks,选择Tasks:Configure Default Build Task,再选择C/C++: g++.exe build active file。然后会产生task.json和launch.json两个文件。
如果没有产生这两个文件,可以在C++工作区的文件夹创建这两个文件夹,如下所示。
{"version": "2.0.0","tasks": [{"type": "shell","label": "g++.exe build active file","command": "D:/ProgramFiles/MinGW-w64/mingw32/bin/g++.exe","args": ["-g","${file}","-o","${fileDirname}${fileBasenameNoExtension}.exe"],"options": {"cwd": "D:/ProgramFiles/MinGW-w64/mingw32/bin"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true}}] }
1234567891011121314151617181920212223242526 将launch.json内容也覆盖,需要将miDebuggerPath的位置更改为自己的目录。 注意(如果有报错,报错原因如下)这里的路径是 gdb.exe 的路径,上面是 g++.exe的路径,路径错误时会报错 g++.exe: error: unrecognized command line option '--interpreter=mi。
{ // 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", "preLaunchTask": "g++.exe build active file", "type": "cppdbg",//只能为cppdbg "request": "launch", "program": "${fileDirname}${fileBasenameNoExtension}.exe",//调试程序的路径名称 "args": [],//调试传递参数 "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:ProgramFilesMinGW-w64mingw32bingdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
123456789101112131415161718192021222324252627282930如上配置完成。
如果这篇文章帮助到公子/小主您了,请动动您的小手指,给博主点个赞吧!江湖生存不易,感谢您的观看。