Reputation: 49665
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:
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
Upvotes: 8
Views: 76823
Reputation:
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.
Upvotes: -1
Reputation: 61138
Are you sure you installed g++? G++ is C++ compiler, not C compiler. If you only installed C compiler, you would have command gcc but not command g++
Upvotes: 2
Reputation:
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 :-)
Upvotes: 3
Reputation: 36663
bring up dos shell.
cd c:\cygwin\bin
type c++ or cpp
or do a directory command do see the contents. Look for cpp or c++.
If they aren't there, you haven't downloaded it.
Upvotes: 1
Reputation: 49665
Ah, I have thought that g++ is installed when I install cygwin. So, I should actually first install g++ in that case, shouldn't I?
(and then reboot)
Upvotes: 3
Reputation: 116674
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.
Upvotes: 2
Reputation: 12195
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.
Upvotes: 0
Reputation: 3857
To get the path in cygwin:
echo $PATH
This will get us on the road to understanding the problem.
Edit:
The next command will tell us where cygwin thinks it should be looking for all those files within windows
mount
The line which includes /usr/bin is the one we need a copy of.
Upvotes: 1
Reputation: 4778
make sure it's on the path or you're running the bash shell cmd prompt.
Upvotes: 2
Reputation: 36663
In addition to adding it to the path (which will fix your problem), you may want to download make and dbg, which are also on the development path but not checked by default. Make sure to select "keep" as the overall install options so it doesn't re-download everything.
Upvotes: 0
Reputation: 607
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.
Upvotes: 2