Compiling C++ on a Mac

Though the Mac isn't officially supported at CSU, there's probably and IDE that you can download for your Mac that looks very similar to the one we use in class. Still, one of the simplest ways to compile your program is using the program g++.  You will do this using the command line (terminal), which is usually found under the 'Applications' folder, and then the 'Utilities' folder.  Note, you may want to drag this onto your program bar at the bottom of the screen for future access.  Typically, you will do the following steps:

  1. Open up the terminal, as well as some kind of editor (like word pad). You can alternatively do this from the command line, but use whatever you're comfortable with.
  2. Edit/change your program (for example, my.cpp).
  3. Save your changes, remembering the folder that you put it in.  For simplicity, you may want to create a CSCI1301 folder directly in your hard drive (root directory)
  4. From the terminal, you will make sure you're in the same directory as your .cpp file, then type g++ -o myprogram my.cpp
  5. The step above compiles my.cpp (source code) into an executable called 'myprogram'.  You can then run it by typing ./myprogram
  6. Go to step 2 until your program works.

Note: if you're not a Unix guru, don't sweat it.  You can change directories by typing 'cd' and then the directory you want to go to.  If you've set it up correctly (by creating the csci1301 folder), before you compile the first time, you can type cd /csci1301 and you will be in the right directory.

You may want to check out the Mac site for a program called Eclipse.  It seems to be pretty powerful, and I think it's free.