Installing a C++ Compiler on Your Own PC

Steven J. Zeil

Last modified: May 21, 2019

This document will walk you through the process of installing a free C++ compiler on your PC.

Do you need to do this?

I assume that you are here because you want the ability to do at least some of your programming work on your own PC. You do have the option, though, of connecting remotely to CS Dept machines and doing all your work there.

So, no, ODU CS students don’t **need* to do this. But many will find it convenient to put together a programming environment on their own PCs.

What will you need to get?

By the end of this process, you need to have installed

What will this let you do?

It will let you compile, run, and debug C++ code when working from the command line.

Of course, most people don’t want to do all of their work from the command line. Furthermore, conspicuously missing from this list is any means of creating or editing code.

That’s because a compiler is a very specific thing – a program that translates your programming language source code into an executable. A compiler is not a program that allows you to create, edit, run, test, & debug your code. Code::Blocks, Eclipse, XCode, etc. are not compilers – they are IDEs.

You’ll want an IDE

An IDE (Integrated Development Environment) is a program that “surrounds” a compiler and provides support for a variety of programming activities, including writing code, compiling it, correcting errors, running and testing the resulting program, and debugging the program.

The most popular IDEs for C++ programming at ODU are Code::Blocks and Eclipse. Both IDEs are free, and both can be installed on Windows, OS/X, and Linux PCs.

In most cases, though, you want to install your compiler and make sure it’s working before you install your IDE.

Decision Time

The first big decision is one that you have already made:1 What is the operating system of the PC on which you are going to be working?

1 Installing a C++ Compiler in Linux

If you are running Linux on your PC, you presumably already know how to install new software packages in your Linux distribution. This is just another package.

Follow the usual procedure for installing packages on your system and get the latest versions of

2 Installing a C++ Compiler on Apple OS/X

g++ is no longer available as an official Apple distribution. However, you can obtain the clang C++ compiler, a worthy “competitor” to g++ that has a very loyal following, in a package called “Command Line Tools for XCode” available from Apple’s developer Site.

That should also install gdb and make as well.

3 Installing a C++ Compiler on Microsoft Windows

You have two main options here, CygWin and MingW.

Both the Code::Blocks and Eclipse IDEs will work with either CygWin or MinGW.

If you have decided that you are going to install Code::Blocks as your IDE, you have the option of stopping right now and moving directly to installing that IDE. That’s because Code::Blocks for Windows is distributed in two flavors: one with no compiler of its own, and the other pre-packaged with a version of the MinGW compiler.

3.1 Installing the CygWin Compiler

If you prefer the MingW version, jump to the next section.

  1. Go to the CygWin site and follow the directions to download and then run the CygWin installer program.

  2. I recommend just installing the basic, default CygWin system on your first “pass” without adding any optional packages (including the compiler).

  3. Check your installation to make sure it works. You should have a new Start menu entry to run a CygWin terminal. Try it and make sure that it works. It should run a bash command shell that accepts commands like:

    • pwd: to print your current working directory location
    • ls: to list the files and directories in your current working directory
    • cd directory : to change your current working directory location
    • exit: to close the terminal session.
  4. If everything looks good, re-run the CygWin setup program and add the following: g++, gdb, and make.

  5. Check your installation to make sure it works. Start a CygWin terminal again. Give the commands

    g++ --version
    gdb --version
    make --version

    Each should result in a message indicating that the program started successfully.

Skip forward to Add the Compilers to your PATH.

3.2 Installing the MinGW Compiler

  1. Go the the MinGW site and follow the directions to download and then run the MinGW installer program.

    Install the following: mingw-developer-toolkit, mingw32-gcc-g++, mingw32-gdb, msys-base, msys-make

  2. Check your installation. Open a Windows cmd window. (Click the Windows start button and type “cmd”). Step down to the bin directory inside the directory where you installed MinGW, for example, if you installed it in the default location of C:\MinGW, then you should do

    cd \MinGW\bin

    Give the commands

    g++ --version
    gdb --version
    mingw32-make --version

    Each should result in a message indicating that the program started successfully.

3.3 Add the Compilers to your PATH

The %PATH% in Windows is the list of directories where Windows will search for executable programs.

  1. Whichever compiler you choose, add the bin directory containing the g++ and other compiler executables to your Windows PATH. Whatever IDE you install later, this step will help the IDE find your compiler (especially if you did not install them in the default location.)

  2. Check that you have done so successfully: Open a Windows cmd window. (Click the Windows start button and type “cmd”).

    Enter the following commands:

    g++ --version
    gdb --version
    make --version

    (If you installed MinGW, change the make command above to mingw32-make.) Each should result in a message indicating that the program was located and started successfully.

4 What Now?

Next it’s time to install an IDE.

1: : Actually, even that decision can be worked around. Some students use VirtualBox or similar packages to run Linux virtual machines on their Windows/Mac PCs. Windows 10 users also now have the option of running Ubuntu Linux within a “sandbox” on Windows.