简体   繁体   English

Windows 无法识别 g++ 或 gcc

[英]Windows not recognizing g++ or gcc

I downloaded the MinGW compiler for c and c++, I executed the installer and added the MinGW bin directory to the environment variables.我下载了 c 和 c++ 的 MinGW 编译器,我执行了安装程序并将 MinGW bin 目录添加到环境变量中。

在此处输入图像描述

After that I tried to execute g++ --version on the cmd and I got the following error:之后,我尝试在 cmd 上执行 g++ --version 并收到以下错误:

'g++' is not recognized as an internal or external command, operable program or batch file. 'g++' 不是内部或外部命令、可运行程序或批处理文件。

I have closed and opened again the cmd and restated my computer but the error persists.我已经关闭并再次打开 cmd 并重新启动我的计算机,但错误仍然存在。

System variables are basically globally set variables which all have different meaning to the system.系统变量基本上是全局设置的变量,它们对系统都有不同的含义。 The Path variable is what you want to take a closer look at, as it is the Variable which is queried by the console whenever you type a programs name into the prompt. Path变量是您想要仔细查看的内容,因为它是每当您在提示中键入程序名称时控制台都会查询的变量。 It will look into all direcories specified in the value of the Path variable and search for the program you entered.它将查看Path变量值中指定的所有目录并搜索您输入的程序。

So it doesn't really help if you create MinGW as a custom variable.因此,如果您将 MinGW 创建为自定义变量,它并没有真正的帮助。 What you want to do is add your path c:\MinGW\bin to the Path variable.您要做的是将您的路径c:\MinGW\bin添加到Path变量中。

I'd recommend a reboot after that to make sure, the changes take effect.我建议在此之后重新启动以确保更改生效。

You're adding the directory to the system variables, which are global and cannot be changed by any user.您正在将目录添加到系统变量中,这些变量是全局的,任何用户都无法更改。 They are set by Windows itself, and any other programmes or drivers installed.它们由 Windows 本身以及安装的任何其他程序或驱动程序设置。 Instead, you should be adding C:\MinGW\bin to the user variables right above the system variables in the Environment Variables.相反,您应该将C:\MinGW\bin添加到环境变量中系统变量正上方的用户变量中。 Specifically, the value should be added to the Path variable (see this screenshot).具体来说,应该将值添加到Path变量中(参见屏幕截图)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM