Installing c++/g++ on Mac OS X

October 6, 2020

Disclaimer: This page is being maintained mainly for my students. Use these instructions at your own risk. There is no warranty in any form or shape whatsoever!. There is no guarantee that these instructions are up-to-date. With that understood you may continue with the rest of this page if you choose to accept these terms.

Go to https://developer.apple.com/xcode/ and download and install a version of Xcode that would work on your Mac.

Once you install it, you can compile and run a C/C++ program, e.g., hello.c (or hello.cpp) from command line as follows:

  > gcc -g hello.c -o hello -lm                         // To compile hello.c
  > g++ -g hello.cpp -o hello -lm                       // To compile hello.cpp

  > hello    or ./hello if ./ is not included in PATH   // To run

If you want to run it in Xcode rather than from command line, learn how to use Xcode. This simple YouTube video was a pretty good start, I found.

If you've installed Emacs, you will also be able to run g++ from Emacs. If you want to learn how to run g++ in emacs, see here.

That's it!


Maintained by Art Lee (alee at cmc dot edu).
Last modified . . .