C++ g++ 不适用于 Windows 命令提示符。安装了 Cygwin
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/637953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
g++ not working on Windows command prompt. Cygwin installed
提问by Shane
I have installed Eclipse and CDT (to use C/C++ in eclipse CDT is needed), as well as installing Cygwin so that I can compile my files.
我已经安装了 Eclipse 和 CDT(需要在 Eclipse CDT 中使用 C/C++),以及安装 Cygwin 以便我可以编译我的文件。
In environment variables I've set Path to include the following: "C:\cygwin\bin;"
在环境变量中,我将 Path 设置为包括以下内容:“C:\cygwin\bin;”
g++, make and GDC are all installed via Cygwin. I made sure of this by searching for them in the bin folder - they're all there.
g++、make 和 GDC 都是通过 Cygwin 安装的。我通过在 bin 文件夹中搜索它们来确保这一点 - 它们都在那里。
If I enter "make" into the windows command prompt, this appears:
如果我在 Windows 命令提示符中输入“make”,则会出现:
make: *** No targets specified and no makefile found. Stop.
If I enter "g++" or "gdc" into the windows command prompt, this appears (or similar):
如果我在 Windows 命令提示符中输入“g++”或“gdc”,则会出现(或类似):
'g++' is not recognized as an internal or external command,
operable program or batch file.
So, in other words make is working but the rest isn't..but they're in the same bin folder! Has got me completely confused.
所以,换句话说 make 正在工作,但其余的不是......但它们在同一个 bin 文件夹中!让我完全糊涂了。
If I attempt to open Cygwin Bash Shell, g++, make and GDC all work there.
如果我尝试打开 Cygwin Bash Shell,g++、make 和 GDC 都可以在那里工作。
However, I need it to work in the command prompt so that Eclipse is able to compile the programs I write in the IDE.
但是,我需要它在命令提示符下工作,以便 Eclipse 能够编译我在 IDE 中编写的程序。
If you know why this is happening, please let me know.
如果你知道为什么会这样,请告诉我。
回答by hasen
回答by ylu
Here is what happened to me and how I fixed it. My C:\cygwin\bin\g++.exe is a shortcut pointing to C:\etc\alternatives\g++.exe, which points back to C:\cygwin\bin\g++-3.exe. Replacing g++ with g++-3 worked for me.
这是发生在我身上的事情以及我如何解决它。我的 C:\cygwin\bin\g++.exe 是指向 C:\etc\alternatives\g++.exe 的快捷方式,它又指向 C:\cygwin\bin\g++-3.exe。用 g++-3 替换 g++ 对我有用。
回答by Laurens
Adding the cygwin paths to the Path variable worked for me (windows 8.1 64 bit):
将 cygwin 路径添加到 Path 变量对我有用(Windows 8.1 64位):
Go to system properties and select advanced system properties
转到系统属性并选择高级系统属性
Go to environment variables and select Path in system variables, click edit
转到环境变量并在系统变量中选择路径,单击编辑
Add the Cygwin paths... for 32 bit:
添加 Cygwin 路径...对于 32 位:
C:\Cygwin\bin;C:\Cygwin\usr\bin
for 64 bit:
对于 64 位:
C:\Cygwin64\bin;C:\Cygwin64\usr\bin
回答by Newb
In C:\cygwin\bin see whether g++.exe is there. If not, the installation wasn't done properly and you may need to install again. That's what was my problem and it's resolved :)
在 C:\cygwin\bin 中查看 g++.exe 是否存在。如果没有,则安装未正确完成,您可能需要重新安装。这就是我的问题,它已经解决了:)
回答by Newb
In the CMDwindow, try typing bashto start a bash shell in that window. If that doesn't work, then the cygwin bin directory is not on your path.
在CMD窗口中,尝试输入bash以在该窗口中启动 bash shell。如果这不起作用,则 cygwin bin 目录不在您的路径上。
If it did work, enter type g++and type maketo see the paths that are being used for these commands. I'm pretty sure your problem is with your PATH variable.
如果确实有效,请输入g++并输入 make以查看用于这些命令的路径。我很确定你的问题出在你的 PATH 变量上。
回答by unwind
You could install a Windows version of whichto get some help in figuring out exactly which executables are being run.
您可以安装一个Windows 版本,以便在确定正在运行的可执行文件方面获得一些帮助。
Perhaps it's picking up 'make' from somewhere completely different, and your addition to %PATH% is not working.
也许它是从完全不同的地方获取“make”,而您对 %PATH% 的添加不起作用。
Also verify it by typing echo %path%
in the same command prompt window as you're seeing the problem in, just to make sure.
还可以通过echo %path%
在与您看到问题相同的命令提示符窗口中键入来验证它,只是为了确保。