Eclipse CDT on Mac OS X

Nowa­days, it seems that the Eclipse C/C++ Devel­op­ment Tools (CDT) is quickly becom­ing a de-facto stan­dard espe­cially for Embed­ded Devel­op­ment. As Bill Gra­ham points out, this is mainly the result of the efforts of embed­ded tools ven­dors or RTOS ven­dors, who have extended the CDT for cross-development envi­ron­ments with remote tar­get debug­ging and the like.

Recently I’ve worked with Eclipse-based Nucleus EDGE from Men­tor Graph­ics as an embed­ded IDE with Microtec com­pil­ers for a Cold­Fire tar­get and was quite pleased with the over­all devel­op­ment envi­ron­ment (com­par­ing this to the old Nucleus EDE some years ago which was a set of macros to be imported in Microsoft Visual Stu­dio 6, which led me to use vim and make on Cyg­win as my main devel­op­ment tools. btw, if you are like me and vim is indis­pens­able to you, then you can add vi func­tion­al­ity to Eclipse with viPlu­gin — this one is com­mer­cial, but there exists other plu­g­ins as well).

Now, as I’ve had some time to spend on my Mac­book Pro, I wanted to know what the “vanilla” Eclipse CDT from has to offer for build­ing self-hosted C/C++ appli­ca­tions with stan­dard GNU C/C++ tools (the Apple GCC 4.0 com­piler in that case).

As exam­ple source code I decided to use the famous rotat­ing 3-D gear wheels from Brian Paul that has been con­verted to GLUT. The source code is in the pub­lic 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 Util­ity Toolkit (GLUT) can be installed with Mac­Ports.

$ sudo port install glut

Then com­pile the pro­gram 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 famil­iar, no? :-)

Now, on to the instal­la­tion of the CDT release for Europa based Eclipse. CDT 4.0 runs with Eclipse 3.3 and is part of the Eclipse Europa simul­ta­ne­ous release. I’ve installed CDT 4.0.2 by enter­ing the URL

in the Eclipse update man­ager to down­load the CDT features.

First open the C/C++ perspective

Then cre­ate an empty C project and select the Apple GCC toolchain.

Add the include direc­to­ries /opt/local/include and /usr/X11R6/include in the project properties.

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

After suc­cess­ful com­pi­la­tion, you will prob­a­bly want to run the gears appli­ca­tion, but you’ll see the fol­low­ing error mes­sage in the con­sole

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

This can be fixed by adding the dis­play vari­able to the environment

Now you should be able to com­pile and run the gears appli­ca­tion from Eclipse CDT in Mac OS X. :-)

9 thoughts on “Eclipse CDT on Mac OS X”

  1. For me it didnt seem to suf­fice with just doing a sudo port install glut it says it is installed and acti­vated but from eclipse (nor from com­mand line) it cant find glut it keeps say­ing “ld:library not found for –lglut”

  2. Looks like GLUT no longer is avail­able by that com­mand on mac­ports if any­one is still read­ing this arti­cle they should write “sudo port install mesa” instead glut seems to be included in that port.

  3. Well, I am run­ning Mac OS X 10.6.3 and I was able to fol­low the tuto­r­ial as is. Includ­ing the “sudo port install glut” com­mand. Nice work, thank you!

  4. Hi

    Thanks for the tuto­r­ial. As a novice this has helped me get into Eclipse. Nearly there with the C++ ver­sion of Eclipse (Ver­sion: 3.3.2 Build id: M20080221-1800) and got rid of a make error by using inter­nal CDT option in C/C++ Build in Project Prop­er­ties but I am still get­ting symbol(s) not found error

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

    Any ideas?

    Time con­sumed: 623 ms. )

  5. Great!
    Worked fine for me!
    I’m impressed that a com­puter related arti­cle is actual even after almost 4 years.
    Respect for the arti­cles author.

  6. For real on some mac sys­tems it keeps com­plain­ing about libraries in the linker thing. always a ‘library not found for –lXXX’ e.g. –lglut for some insane rea­son! Every­body on every web­site says this works and I have been on it for days but its not work­ing. I even tried it on com­mand line using the following

    gcc –Wall –IincludesOpenCV/ –LOpenCV/lib/ –lcv –lhigh­gui –lcx­core –o try main.cpp

    The /lib direc­tory con­tains files cv.lib, highgui.lib and cxcore.lib. I have also tried *.a files as well

    Any­one know if theres some­thing some­where else in the eclipse set­tings that is pre­vent­ing it from work­ing? I will really appre­ci­ate your input.

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

Leave a Reply