CodeBlocks on a Macintosh

You probably read the post entitled, “Getting CodeBlocks to Work” regarding my book, “C++ All-In-One Desk Reference For Dummies“, and immediately thought it didn’t apply because you have a Macintosh. Rather than write a single confusing post, I decided to write a second post just for Macintosh developers.  Here are the instructions for the Macintosh:

  1. Go to this page: http://www.codeblocks.org/downloads/5 .
  2. Download the Macintosh version of the compiler, codeblocks-8.02-p2-mac.zip. That contains the compiler.
  3. Double click the file once the download is complete and follow the instructions to install the compiler.
  4. At this point, start the CodeBlocks compiler.  Once it has started up, select Settings -> Compiler and Debugger. In the Compiler and Debugger Settings dialog box, click the “Selected Compiler” drop down and choose the GNU GCC Compiler option.  You should be good to go at this point.


I wrote these instructions with the help of a friend with a Macintosh. While the examples in the book work just fine on a Macintosh, I don’t have a lot of Mac experience. If this fix doesn’t work, we may have to work together a bit to come up with a solution.  This solution did work for two other Macintosh readers, so I’m hoping it also works for you, but I’m more than happy to work with you to make sure you get a working setup. Feel free to write me at John@JohnMuellerBooks.com with your ideas and suggestions for a better procedure. You must have a copy of Mac OS X 10.4 or later to use CodeBlocks!

Getting CodeBlocks to Work

One of the most common e-mails I receive about C++ All-In-One Desk Reference For Dummies is that people are receiving an error message about the compiler when they try to compile the examples. A common error message is:

SayHello2 – Debug uses an invalid compiler. Probably the toolchain path within the compiler options is not set up correctly?! Skipping … Nothing to be done.

The reason you’re having trouble is due to an error on the CD.  It turns out that our production folks made a mistake in putting the book’s CD together. The product that we have on the CD is the IDE only and does not include the compiler.  There is a quick solution to the problem should you wish to use it:

  1. Go to this page: http://www.codeblocks.org/downloads/5.
  2. Download the second item on the list, codeblocks-8.02mingw-setup.exe. That contains the compiler.
  3. Double click the file once the download is complete and follow the instructions to install the compiler.


If you’re using Windows Vista or Windows 7, the version of the MinGW compiler that comes with CodeBlocks might not work.  (It does work on my copy of 64-bit Windows 7 and many other people have used it successfully, but a few people do run into problems.)  In this case, you’ll need to go to http://www.mingw.org/
to download the latest version of the MinGW compiler as they suggest on the CodeBlocks Web site.  You can also get the latest version of the compiler from http://sourceforge.net/projects/mingw/files/Automated MinGW Installer/.  My writing partner, Jeff, suggests that you install:

  • MinGWbaseTools
  • g++ compiler
  • MinGW Make


into
C:\MinGW to make the compiler easier for CodeBlocks to find.  At this point, start the CodeBlocks compiler.  Once it has started up, select Settings -> Compiler and Debugger. In the Compiler and Debugger Settings dialog box, click the “Selected Compiler” dropdown and choose the GNU GCC Compiler option.  You should be good to go at this point.  Please let me know if you experience any other problems at John@JohnMuellerBooks.com.

Using the Book’s Source Code

At least some readers try to hand type the source code found in C++ All-In-One Desk Reference For Dummies. Working with source code when you’re learning a new programming language is hard enough; typing it in by hand and getting a good result is nearly impossible in many cases. I recommend that you always use the code from the book’s CD so that you can avoid potential typos. If you experience problems using the code from the book’s CD, please query me at John@JohnMuellerBooks.com; there may be something that isn’t set up correctly on your system.  The examples on the CD should compile and work, but I always emphasize the word “should”
because each system and setup is slightly different (making things exciting for all of us).

To use the code on the CD, follow these steps:

  1. Copy the Author folder from the CD to your hard drive.
  2. Right click the Author folder and choose Properties from the
    context menu.  You’ll see the Author Properties dialog box.
  3. Clear the Read-only check box. Click OK. You’ll see a Confirm
    Attribute Changes dialog box.
  4. Click OK. Windows will remove the read-only attribute from all
    of the files. You’re ready to begin using the source code supplied with the
    book.

To use a particular example, navigate to that examples folder under the Author folder.  Say you want to work with the AddInteger example in Book I Chapter 2.  You’d navigate to the \Author\BookI\Chapter02\AddInteger.  To open the project, simply double click the associated .CBP file.  In this case, you’d double click the AddInteger.cbp file and CodeBlocks will open with the example loaded and ready for you to work with.