C/C++ with Eclipse Galileo on Mac OS 10.6

Getting Eclipse to compile your C/C++ applications on Linux has always been a breeze.  On Windows, it’s always been hell.  And on Mac, it’s somewhere in between.

Here’s what you need to get started:

Your Mac OS install DVD has a few optional components that aren’t part of the standard installation.  One of these is XCode, which is Apple’s wonky IDE.  It comes with the GNU toolchain, which is exactly what you’ll need.  If you’ve installed the right thing, you should be able to open a new terminal window (note: a NEW terminal window) and run “gcc”.  If it’s installed, it will return with something like “gcc: no input files.”  Which is true — you didn’t give it any input files.

Now onto the next problem.  Eclipse’s C/C++ Development Tools (CDT) plugin doesn’t work with 64-bit binaries without some significant tweaks because it won’t recognize the binary as a valid application. And on Snow Leopard, GCC compiles 64-bit by default.  Damn!

There’s two workarounds for this, use whichever one suits you best (but not both!):

  1. Switch back to 32 bit binaries. In each project, right click and select Properties, and open the C/C++ Build section, and click settings.  Under MacOS X C++ Linker, click Miscellaneious.  There’s three text fields; in the one that just says Linker flags, add “-arch i386” (without the quotes).  Then go to the GCC C++ Compiler section, hit Miscellaneous, and add the same text to the Other flags box.  Now you just need to do a clean build, and you should be good to go.
  2. Don’t use the Run dialog.  You can use the Run External command to run the 64-bit executable.  This can be somewhat annoying if you have several build options, or you like changing the name of your project.  But it works.

Remember, you only need to make ONE of the above changes. Don’t make both!

Hopefully this helped someone out there.  And even more hopefully, this will be fixed in the next verison of Eclipse.

Update: forgot the “i” in “i386” and added emphasis about only making one of the two changes.