VSCode配置C++环境【报错interpreter=mi】


VSCode配置C/C++环境

博客参考大佬

报错: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

  1. 按快捷键 Ctrl+Shift+P调出命令面板,输入tasks,选择Tasks:Configure Default Build Task,再选择C/C++: g++.exe build active file。然后会产生task.jsonlaunch.json两个文件。

    如果没有产生这两个文件,可以在C++工作区的文件夹创建这两个文件夹,如下所示。

在这里插入图片描述

在这里插入图片描述

  • task.json内容复制进去,需要将commandcwd的位置更改为自己的目录。
{
	"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
			}
		}
	]
}
  • 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:\\ProgramFiles\\MinGW-w64\\mingw32\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

如上配置完成。

如果这篇文章帮助到公子/小主您了,请动动您的小手指,给博主点个赞吧!江湖生存不易,感谢您的观看。😊😊😊

  • 28
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值