How To Run C++?

There are many ways to compile and run C++ programs. For this course, we'll be running text-based standard C++ programs, so there should be no requirement for any particular platform. You need to be able to do two things:

  1. Edit, compile and run C++ code, using any tools you like and can get working.
  2. You need to be able to compile and run programs from the command line, even if you don't do it routinely. A few things just work better that way, and you need to know all the tools in the box.

Below are several ways to do all this. All the software mentioned here is free to use.

Run Linux

C was developed to run Unix, and there is a long historical connection. One of best ways to use C++ is in its home, on the Unix clone known and Linux. Linux is a free OS having many distributors, each of which gives a slightly different flavor to their version. Any Linux distro will have command-line C++ compiler and some variety of editors and IDEs, though you may have to install them from the distro repository. A repository is much like an app store, but less pretentious.

There are many ways to run Linux:

  1. You can install one of the many free Linux distributions, such as Fedora (my favorite), Ubuntu, Arch, or many others. These can be installed and used on a USB jump drive to create a dual boot system without disturbing your existing hard drive or OS.
  2. If you run Windows, you can use the Windows Subsystem for Linux, which basically runs a Linux system on Windows. (MS apparently noticed that way to get the most from Windows is to run something else.) Here are some official instructions, and some others, for setting that up.
  3. You can run Linux on a virtual machine. If you don't have a Virtual Machine Manager handy, you can install Virtual Box. This site has VM images you download and run once the VMM is installed. Some newer or premium versions of Windows can run Microsoft's hyper-V, in which case may be the easiest VMM to set up.

Run on Windows

To run on Windows without a VM or WSL, install the mingw compiler using the instructions here. It's a bumpy install, but the linked instructions are very helpful. However, you should click this for Windows 11. If the part about setting the path doesn't match your Windows version, try here. After following these instructions, you will be able run the c++ (or equivalent g++) command from the command line. Also, if you have JGrasp installed, it will magically start being able to compile C++ programs since it can now find a C++ compiler.

If you want to add an IDE, many students seem to like Visual Studio, and it is widely used. The installation instructions above assume the user will install an IDE called Eclipse, which you may do if you like. It was originally made to build Java programs, but apparently works with other languages as well.

Run On Mac

I don't have access to a Mac, so you are going to be pretty much on your own with this. Here are a two randomly Googled sets of instructions that may be of some use. You can provide additional randomly-Googled links as needed. Both of the given ones involve installing XCode, which apparently includes a full development environment, including the ability to compile and run from the Terminal app, as also needed. The XCode home is here, which might help you get started with that.

JGrasp and Visual Studio should work on Mac as well.

The Mac kernel is a Unix derivative. Historically, Mac is more closely related to Unix than Linux is. But that's a long and fairly irrelevant story.

Compiling and Running From the Command Line

I generally work with a text editor and the command line, so I don't use an IDE. You may use any you like, but, as noted above, you do need to be able to compile and run from the command line when needed. If you install mingw using the instructions above, the g++ command will work from the Windows cmd. This will happen naturally on Linux or MAC, since Windows is the only OS broken enough to make this an issue.

No matter which of these approaches you use, you will be using one of two compiler packages. Linux uses the GNU Compiler Collection (GCC), which has the gcc plain C compiler and g++ C++ compiler. MinGW is a Windows port of GCC. This name is derived from “Minimal GNU Windows”. (Minimal is probably meant to contrast with other projects intended to implement a large part of the Unix environment under Windows.) GNU certainly runs on Mac, but the semi-official compiler set for Mac is LLVM, with the Clang C/C++ compiler. It's usually installed to work like GCC, using the same command syntax, to keep users happy and existing development environments from breaking.

GCC can be installed on Mac. LLVM can run on Linux, and presumably Windows (though I've never looked it up), so these associations are not fixed, but you must never underestimate the Power Of The Default. There are other compilers, especially for plain C, but GCC is still the big kid on the block, so it's not going away. LLVM is newer, and well-regarded as having taken some of the right lessons from its predecessors, so it's not going anywhere, either. C++ is a beastly difficult language to compile. None of which makes much difference for an introductory C++ course.