I am trying to execute my first "Hello World!" in C++. I am using Windows XP, and I have installed cygwin, in which the g++ C++ compiler is installed. I have written a small hello-world program, and saved it in hello.cpp. From the command prompt I write:
g++ hello.cpp
But I get:
'g++' is not recognized as an internal or external command, operable program or batch file.
I have installed cygwin in my D:\programs\cygwin. I have made another directory with my hello-world file in D:\cpp. Something with my installation or my paths seems to be not Ok, but I cannot figure what. I have run the exe file of cygwin, and in the installation directory I have got all necessary files, I think: bin folder, lib, Cygwin.bat, etc.
I have read that in case of such error message I should check whether the cygwin1.dll file is copied into the main folder of Windows. Is this the C:\WINDOWS directory? I have looked there, and I don't have such a file there. I have cygwin1.dll in the bin folder of cygwin: D:\programs\cygwin\bin. Also, how do I check whether the bin folder (D:\programs\cygwin\bin) is considered in the search path of commands?
I think that the hello-world program shouldn't contain any syntax errors, I have just copied it. Also, when I write
g++ -v
I get the same error message: that the command is not recognized. I would appreciate if someone give me a hint what should I look at. Thank you.
Here is the code of the hello-world program:
#include <iostream>
using namespace std;
int main() {
cout <<"Hello World!"<<endl;
return 0;
}
I have installed g++, and now when I type g++ -v, I get: Reading specs from: \d\cygnus\cygwin-b20\H-i586-cygwin32\bin..\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\specs gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
In the bin directory I have both g++.exe, and gcc.exe. I don't understand why I get "gcc" above and not "g++". I don't know how important this is, but I receive an error message when I try to compile the program in the DOS command prompt:
g++ hello.cpp
I get:
hello.cpp:1: parse error before character 0357
hello.cpp: In function 'int main()':
hello.cpp:'cout' undeclared (first use this function)
hello.cpp: (Each undeclared identifier is reported only once
hello.cpp: for each function it appears in.)
hello.cpp: 'endl' undeclared (first use this function)
And here is what I get when I try to compile the program in the cygwin shell:
hello.cpp:1: parse error before character 0357
hello.cpp: In function 'int main()':
hello.cpp:'cout' undeclared (first use this function)
hello.cpp: (Each undeclared identifier is reported only once
hello.cpp: for each function it appears in.)
hello.cpp: 'endl' undeclared (first use this function)
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
g++.exe: hello.cpp: No such file or directory
g++.exe: No input files
I am assuming you are using the Windows Shell here. If you invoke the compiler from a cygwin Bash shell, all the paths should be set for you.
Try to create a new file and type in the code yourself without copying and pasting it. You may have an illegal character in your code which may not be visible in your editor of choice.
Make sure they c:\cygwin\bin is in the PATH.
Hope it helps.
I wrote a tutorial about this a few years ago, which might help:
http://www.codeguru.com/cpp/misc/misc/compilerandpre-compiler/print.php/c8107__1/
Did you install g++? It's not installed by the default settings of the Cygwin installer.
As others have mentioned, it's probably a path issue, so you need to look at the environment variable PATH. To do this, right click on
My Computer
and click "Properties". Go to the "Advanced" tab and click the "Evironment Variables" button. From here, see if the paths you mentioned are included in the PATH variable. If not, add them using the same syntax you see there to separate paths (I think it's a semi-colon or a colon between paths.)Edit: Ah, I see you've already done this (beat my post by mere seconds.) I think all you need to do now is reboot.
As people have said, check the path. Don't start copying the cygwin DLLs around - that is not necessary, may cauxse problems later and won't solve the problem.
And when it comes to setting the Windows PATH variable (and others) I've found this small program to be quite useful and better than squinting at the MS control panel aplet.
Edit: It seems the OP had mistakenly not installed g++ - a lesson for all of us who replied in asking the obvious question first :-)