g++ Resources

The C++ compiler g++ is part of the GCC (GNU Compiler Collection) compiler suite. GCC is a multi-platform, freely-available, open-source compiler suite.

The g++ compiler is available on many of the department machines, including loki, forrestal, iowa and trident. In addition, it can be installed easily in Cygwin and used on MS Windows.

Using g++

We are using g++ version 3.4.4. You can type in the following to use it:

g++

Use the following to check the version:

g++ --version

Note that there are two dashes before the version flag.

You should see something similar to the following for the first two lines that indicates you are using version 3.4

g++ (GCC) 3.4.4 20050721 (Red Hat 3.4.4-2)
Copyright (C) 2004 Free Software Foundation, Inc.

To compile the program in the file example.cpp use the command:

g++ example.cpp

This will produce an executable program in a file called a.out in the current directory. You can run this executable program by using the command:

./a.out

That is a dot then a slash before the filename.

To produce an executable program called example use the command:

g++ example.cpp -o example

This will produce an executable program in a file called example in the current directory. You can run this executable program by using the command:

./example

Again before the filename example there is a dot then a slash.

Documentation