Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help >  Languages >  C++

Installing C++ compilers

To develop C++ programs on your own machine you need to ensure that you have a text editor and a C++ compiler. Soon you'll also need the GLUT graphics libraries too.

Here are some options that have worked for us in the past. Included are instructions on using some libraries too. Note: if you're installing so that you can do the Mars Lander exercise, see the Mars Lander page in CamTools from which the information here has been adapted.

Windows

There are two ways you can go about assembling these tools on Windows. You could install Microsoft's Visual C++ compiler or Bloodshed both of which have a built-in text editor. You would then just need to install Octave and the GLUT graphics libraries to be ready for work after the 1st year. The other option is to install Cygwin. This essentially gives you a version of the Linux operating system that runs on your Windows desktop. Linux provides everything you need, including a choice of text editors, a C++ compiler, Octave and the GLUT graphics libraries.

MacOS

You need to ensure that you have a text editor and a C++ compiler. The first of these is no problem: Mac OS X comes with a perfectly adequate editor called TextEdit, though you might prefer to install Aquamacs, which is a pretty version of the Emacs text editor you have been using in the DPO. Alternatively, you could use the built-in editor in the Xcode integrated development environment (see below).

For the C++ compiler, you will need to install the Xcode development tools from your installation CD (the latest Xcode release is also available on Apple's website, but beware, it is not compatible with older versions of Mac OS X). The installer will ask you a number of questions, the default answer is always fine. There are two ways you can proceed to use the compiler: by typing instructions into a terminal, or from within the Xcode integrated development environment. Both of these options are described in more detail below.

The integrated development environment option

This is the way to go if you don't want to experiment with the Linux way of doing things, but would prefer to stick with the familiar Apple look and feel. In Finder, start Xcode by double-clicking on Devices->Macintosh HD->Developer->Applications->Xcode. The main Xcode menu should appear at the top of the desktop. From the File menu, select New Project. If your Xcode window doesn't have an iPhone OS option, then xcode If your Xcode (version 3.2.1 or higher) window does has an iPhone OS option, then try the following.

(info by ahg) There's a bug in recent Xcode releases which affects stringstreams. To apply a workaround - under the Project menu, select Edit Active Target for your program then the Build option. Scroll down, and you should find a line that says Preprocessor Macros _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1. Delete _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1..

The terminal option

Your Mac runs a version of the Unix operating system (very similar to Linux) with a proprietary front-end desktop. If you want, you can use it just like any other Unix system, by typing commands directly into a terminal. By doing so, you will learn what goes on "behind the scenes" whenever you press a button on some application's shiny graphical user interface!

Start a terminal from Finder's Applications folder (you will find Terminal under the Utilities sub-folder). The terminal runs a standard Unix shell, which is a program that lets you control your computer (run programs, examine the contents of directories, etc) from the keyboard. It typically gives you a prompt, like >, and you can type commands into it. When a program or command has finished, you get the > prompt back.

It would serve you well to learn a few things about the operation of the shell (it's exactly the same as the command line interface to the DPO Linux machines). A good place to start is the first few sections of this excellent tutorial. For example, to launch the editor in such a way that you get the > prompt back in the shell straight away and are able to issue new commands, type aquamacs &.

Here's a quick guide to getting started

Vista

The cygwin installation instruction work on vista

Linux

g++ (a C++ compiler) and emacs (a text editor) are usually available from the command line. To compile a simple program called testing.cc you can do

   emacs testing.cc &

to start an editor. Write the code, save it, and type

   g++ -o testing testing.cc 
   ./testing

to compile then run your program.

Friendlier "Integrated Development Environments" (IDEs) like Anjuta might also be installed by default. You can download geany (the IDE we use in the DPO) for SuSE Linux from the openSUSE_11.0/x86_64 repository.

To compile GLUT graphics programs from the command line try something like

  g++ -O3 -o myprog myprog.cpp -lglut
© Cambridge University Engineering Dept
Information provided by Tim Love (tpl) and Dr. G. Csanyi, Dr AH Gee
Valid XHTML 1.0 Transitional
Last updated: January 2011