Part Three - Testing the GCC C++ Compiler
- Download this "Hello World" test program (hello.cpp), save it in your "Cygwin Home" (see Part One):
C:\Cygwin\Home\username
Note that a file extension of .cpp means "C Plus Plus". Sometimes ".cc" is also used.
- Run cygwin
- Type "ls" and enter, or "ls -l" and enter. These should show the "hello.cpp" file.
- Type the following command, and press enter:
g++ hello.cpp -o hello
This should take a little while, but no error messages should appear. It tells the GNU C++ compiler (g++) to take the input file hello.cpp and make an output file called hello.exe (the -o is for output).
- Type "ls" and enter, or "ls -l" and enter. These should show the "hello.cpp" file and the new "hello.exe" file
- Try typing either of the following and press enter:
./hello.exe
or,
./hello
They should both run your program which prints a simple message to the screen.
- quit Cygwin, either by typing "exit" or clicking on the X in the top right of the screen
- Now run the windows command line ("DOS Screen") by using the Windows start menu, run, and typing in "cmd".
- A black window should appear (often called a "DOS Screen").
- Type in the following to change directory to where we put the hello.cpp file:
cd C:\Cygwin\Home\username
(where username is your Windows username)
- Type "dir" and press enter. You should see the "hello.cpp" and "hello.exe" files.
- Try typing either of the following:
hello.exe
Or:
hello
They should both run the program in the windows command window ("DOS Screen").
- Now we can delete this file using:
del hello.exe
- We can re-compile it from within the windows command line ("DOS Screen") by typing:
g++ hello.cpp -o hello
As before, this will create the hello.exe file.
i.e. You can run the compiler (g++) from inside Cygwin, or in the Windows command prompt (DOS Screen).
- You might have noticed a spelling mistake in the example program (was't should be wasn't). Well lets fix it!
- In windows, using the short cut made in Part I, Step 7, open this folder:
C:\Cygwin\Home\username
(where username is your windows username)
- Open the hello.cpp file (i.e C:\Cygwin\Home\username\hello.cpp) with a text editor (like Notepad)
- Change the text "was't" to read "wasn't", and save and quit the program.
Note (if you are not using Notepad) the file MUST be saved as plain text
- Run cygwin again
- Type "ls" or "ls -l" to make sure you can see "hello.cpp"
- Type "cat hello.cpp" to view the file on screen, and check that the spelling mistake is fixed
- Recompile the program as before:
g++ hello.cpp -o hello
- Run the program as before
./hello.exe
or,
./hello
- Again, you could have done the last few steps using the Windows Command Prompt, instead of the Cygwin Command Prompt.
Installing the X Windows System on Cygwin is next...