g++ not working on Windows command prompt. Cygwin

2019-05-07 19:56发布

问题:

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.

In environment variables I've set Path to include the following: "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.

If I enter "make" into the windows command prompt, this appears:

make: *** No targets specified and no makefile found.  Stop.

If I enter "g++" or "gdc" into the windows command prompt, this appears (or similar):

'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.

If I attempt to open Cygwin Bash Shell, g++, make and GDC all work there.

However, I need it to work in the command prompt so that Eclipse is able to compile the programs I write in the IDE.

If you know why this is happening, please let me know.

回答1:

I haven't used cygwin much, but my understanding is you have to use it from the cygwin bash shell.

if you need g++, make, etc, use mingw, with it, g++ works from the normal windows command line.



回答2:

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.



回答3:

Adding the cygwin paths to the Path variable worked for me (windows 8.1 64 bit):

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:

C:\Cygwin\bin;C:\Cygwin\usr\bin

for 64 bit:

C:\Cygwin64\bin;C:\Cygwin64\usr\bin


回答4:

In the CMD window, try typing bash to start a bash shell in that window. If that doesn't work, then the cygwin bin directory is not on your path.

If it did work, enter type g++ and type make to see the paths that are being used for these commands. I'm pretty sure your problem is with your PATH variable.



回答5:

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 :)



回答6:

You could install a Windows version of which to get some help in figuring out exactly which executables are being run.

Perhaps it's picking up 'make' from somewhere completely different, and your addition to %PATH% is not working.

Also verify it by typing echo %path% in the same command prompt window as you're seeing the problem in, just to make sure.