Eclipse CDT on Mac OS X

Nowadays, it seems that the Eclipse C/C++ Development Tools (CDT) is quickly becoming a de-facto standard especially for Embedded Development. As Bill Graham points out, this is mainly the result of the efforts of embedded tools vendors or RTOS vendors, who have extended the CDT for cross-development environments with remote target debugging and the like.

Recently I’ve worked with Eclipse-based Nucleus EDGE from Mentor Graphics as an embedded IDE with Microtec compilers for a ColdFire target and was quite pleased with the overall development environment (comparing this to the old Nucleus EDE some years ago which was a set of macros to be imported in Microsoft Visual Studio 6, which led me to use vim and make on Cygwin as my main development tools. btw, if you are like me and vim is indispensable to you, then you can add vi functionality to Eclipse with viPlugin – this one is commercial, but there exists other plugins as well).

Now, as I’ve had some time to spend on my Macbook Pro, I wanted to know what the “vanilla” Eclipse CDT from has to offer for building self-hosted C/C++ applications with standard GNU C/C++ tools (the Apple GCC 4.0 compiler in that case).

As example source code I decided to use the famous rotating 3-D gear wheels from Brian Paul that has been converted to GLUT. The source code is in the public domain and can be found here.

$ gcc --version
i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

On Mac OS X the OpenGL Utility Toolkit (GLUT) can be installed with MacPorts.

$ sudo port install glut

Then compile the program with

$ gcc -Wall -I/usr/X11R6/include/ -I/opt/local/include -L/opt/local/lib -L/usr/X11R6/lib -lglut -lglu -lgl -o gears gears.c

Looks familiar, no? :-)

Now, on to the installation of the CDT release for Europa based Eclipse. CDT 4.0 runs with Eclipse 3.3 and is part of the Eclipse Europa simultaneous release. I’ve installed CDT 4.0.2 by entering the URL

in the Eclipse update manager to download the CDT features.

First open the C/C++ perspective

Then create an empty C project and select the Apple GCC toolchain.

Add the include directories /opt/local/include and /usr/X11R6/include in the project properties.

Now the required libraries need to be added to the linker settings.

After successful compilation, you will probably want to run the gears application, but you’ll see the following error message in the console

GLUT: Fatal Error in gears: could not open display:

This can be fixed by adding the display variable to the environment

Now you should be able to compile and run the gears application from Eclipse CDT in Mac OS X. :-)

9 thoughts on “Eclipse CDT on Mac OS X”

  1. For me it didnt seem to suffice with just doing a sudo port install glut it says it is installed and activated but from eclipse (nor from command line) it cant find glut it keeps saying “ld:library not found for -lglut”

  2. Looks like GLUT no longer is available by that command on macports if anyone is still reading this article they should write “sudo port install mesa” instead glut seems to be included in that port.

  3. Well, I am running Mac OS X 10.6.3 and I was able to follow the tutorial as is. Including the “sudo port install glut” command. Nice work, thank you!

  4. Hi

    Thanks for the tutorial. As a novice this has helped me get into Eclipse. Nearly there with the C++ version of Eclipse (Version: 3.3.2 Build id: M20080221-1800) and got rid of a make error by using internal CDT option in C/C++ Build in Project Properties but I am still getting symbol(s) not found error

    (ld: symbol(s) not found
    collect2: ld returned 1 exit status
    Build error occurred, build is stopped

    Any ideas?

    Time consumed: 623 ms. )

  5. Great!
    Worked fine for me!
    I’m impressed that a computer related article is actual even after almost 4 years.
    Respect for the articles author.

  6. For real on some mac systems it keeps complaining about libraries in the linker thing. always a ‘library not found for -lXXX’ e.g. -lglut for some insane reason! Everybody on every website says this works and I have been on it for days but its not working. I even tried it on command line using the following

    gcc -Wall -IincludesOpenCV/ -LOpenCV/lib/ -lcv -lhighgui -lcxcore -o try main.cpp

    The /lib directory contains files cv.lib, highgui.lib and cxcore.lib. I have also tried *.a files as well

    Anyone know if theres something somewhere else in the eclipse settings that is preventing it from working? I will really appreciate your input.

    I am using a macro, lion os, 64 bits if that adds anything.

Leave a Reply