Skip to content Skip to navigation
University of Warwick
  • Study
  • |
  • Research
  • |
  • Business
  • |
  • Alumni
  • |
  • News
  • |
  • About
  • Text only
  • |
  • Sign in
  • Search MOAC
  • Search University of Warwick
  • Search for people at Warwick
  • Search Warwick Blogs
  • Search past exam papers
  • Search video
  • More…

    Molecular Organisation and Assembly in Cells

    • Why MOAC?
    • MOAC Research
    • MOAC Degrees
    • MOAC News
    • MOAC People
    • MOAC Students »
    • Peter Cock »
    • Cygwin »
    • 3 - Testing GCC
    University of Warwick

    Part Three - Testing the GCC C++ Compiler

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

    2. Run cygwin
    3. Type "ls" and enter, or "ls -l" and enter. These should show the "hello.cpp" file.
    4. 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).

    5. Type "ls" and enter, or "ls -l" and enter. These should show the "hello.cpp" file and the new "hello.exe" file
    6. 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.

    7. quit Cygwin, either by typing "exit" or clicking on the X in the top right of the screen
    8. Now run the windows command line ("DOS Screen") by using the Windows start menu, run, and typing in "cmd".
    9. A black window should appear (often called a "DOS Screen").
    10. 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)

    11. Type "dir" and press enter. You should see the "hello.cpp" and "hello.exe" files.
    12. Try typing either of the following:

      hello.exe

      Or:

      hello

      They should both run the program in the windows command window ("DOS Screen").

    13. Now we can delete this file using:

      del hello.exe

    14. 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).

    15. You might have noticed a spelling mistake in the example program (was't should be wasn't). Well lets fix it!
    16. 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)

    17. Open the hello.cpp file (i.e C:\Cygwin\Home\username\hello.cpp) with a text editor (like Notepad)
    18. 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

    19. Run cygwin again
    20. Type "ls" or "ls -l" to make sure you can see "hello.cpp"
    21. Type "cat hello.cpp" to view the file on screen, and check that the spelling mistake is fixed
    22. Recompile the program as before:

      g++ hello.cpp -o hello

    23. Run the program as before

      ./hello.exe

      or,

      ./hello

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

    MOAC DTC, Coventry House, University of Warwick, Gibbet Hill Road, Coventry, CV4 7AL
    Tel. 024 765 75808 moac2 at warwick dot ac dot uk

    How to find us

    MOAC Intranet

    EPSRC logo

    Close this email form
    Page contact: Peter Cock Last revised: Wed 6 Dec 2006
    • Sign in
    • |
    • Powered by Sitebuilder
    • |
    • © MMXIII
    • |
    • Terms
    • |
    • Privacy
    • |
    • Cookies
    • |
    • Accessibility