Getting a C++ Compiler
C++ code can be compiled and run --- usually without any changes --- on any
modern operating system, including Windows, Mac OS X, and Linux. Like Python, choice
of operating system when programming in C++ usually will not change how your program acts.
However, C++ compilers often come packaged with integrated development environments, or IDEs,
that contain a graphical user interface and various tools to help you with programming.
These IDEs sometimes are operating system specific; Microsoft Visual Studio, which we use
in Barret, is one of those: it only works on Windows.
Below, you can find out how to get your own copy of the Visual Studio environment for Windows, or
how to get a similar IDE for Mac. Talk to me if you're using Linux.
Note that just because you've saved a project under Visual Studio in Barret doesn't mean
you can't take the .cpp files from within the project and compile them with a different compiler or
a different IDE; that works just fine.
C++ files (.cpp) are just text files and can be transferred and compiled anywhere. What
doesn't transfer are all the other Visual Studio files that are created with a project;
those are specific to Visual Studio and are only meaningful under Windows.
Windows
If you use a Windows operating system, you
can obtain a free, legal version of Visual Studio 2012 in one of three ways.
Option A: Download the full version of Visual Studio 2012 from Microsoft
DreamSpark. This is the best choice because it gives you the exact same environment
at home as in Barret, though you have to jump through some hoops first.
- Go to Microsoft
DreamSpark and follow the directions for students.
- The software you want is Visual Studio Professional 2012.
- You will need to register with
your Rhodes email address to prove you are a student, but then you will have access to
a number of Microsoft software development products.
- Both the 2013 and 2012 versions
of Visual Studio are available. Barret is still on 2012, and I have not tested the 2013 version for compatibility
with projects saved under 2012. Therefore, to be safe, you should probably get
the 2012 version.
Option B: Download the express version of Visual Studio 2013 from Microsoft.
This option has fewer hoops to jump through, but the express version of Visual Studio doesn't have
all the same features as the full version in Barret. Furthermore, I don't think the project files
are compatible between the express and full versions, so if you like to work on the same project
in both places, you're going to have a hard time.
- Download
Visual Studio 2013 Express for Windows Desktop.
- Note that there is no Visual Studio Express 2012, there is only the 2013 version or
the out-of-date 2010 version. The 2013 version should be fine, but Barret has 2012, so
be aware that your projects may not transfer between them. The .cpp files will copy
just fine, but you may need to re-create your projects.
Mac
Visual Studio is Windows-only, but the C++ language is not platform specific, so there
are plenty of compilers and IDEs for the Mac. One that comes built-in with new
Macs (or can be downloaded for free from the App Store) is called Xcode and
will compile C++ just fine.
Instructions to make a C++ project in Xcode (version 5) once it is downloaded and installed:
- From the main screen, choose Create a new Xcode project, or choose File > New > Project.
- In the left pane, under OS X, choose Application. Then choose Command Line Tool
from the right pane. Choose Next.
- Fill in the Product Name (doesn't matter; it's like a project name in Visual Studio).
Make sure C++ is selected for Type. Choose Next.
- Choose a folder in which to store your project. Choose Create.
- A main.cpp file is created automatically for you. Find it in the left pane and
double click to open it. A main function is already filled in; you can now edit
the code.
- To compile and run, click the "Play" button on the toolbar, or choose Product > Run.