Make your own free website on

Guurk's Stuff


Eclipse How-to

Makefile Tips

How-To: Eclipse with MinGW/ MSYS

Getting Started

I'm going to assume that you already are using MinGW and MSYS. I'm probably silly for doing so, but oh well :)

Java Runtime

You'll need the java runtime on your machine. You can get it here: The Java Download Page . You can download the right package for your platform (Windows?). Use the JDK if you are going to do some java coding, otherwise just get the JRE. I don't think you could use the java runtime that comes with windows, so you really need this. It comes as a nice installer, just like MinGW and MSYS. Be sure to allow the installer to add the 'bin' directory to your path. Bring up a MSYS window and type java -version to check that you are now using the right java. You can also check with which java. It should be in your system32, and as of this document should be version 1.4.2.


Pick this puppy up here: Eclipse Download Page . Right now version 2.1.1 is the latest official release. I wouldn't mess around with the 3.0 stuff yet.

To install eclipse you'll need to unzip and/or untar the file. There is no installer for this because it pretty much runs out-of-the-box. The key here to use with MinGW is that I ended up unzip/taring it into my 'home' directory. I did something like this: unzip /c/downloads/ from my 'home' directory. If you are using a graphical zip tool, just unzip it into your c:/MSYS/home/username or equivalent directory. In the eclipse directory there should be a eclipse.exe file.

Here is the catch on using this; where ever you invoke the exe from, it will create a workspace directory where it stores it's projects. To kind of work around this I created a little script that I called ec that I put in my PATH. Here is what it looks like.

    cd ~/eclipse
    eclipse.exe \&
    cd $OLD

This just makes sure that eclipse is always run in it's own directory, so we don't have 'workspace' directories crudding up all your directory structure. Don't worry, you can put your actual projects whereever you like.

Eclipse Tools Project

Well, that's great! Eclipse is a great IDE for working on java, but we really want to get to using C++ (the TRUE programming language). So, all we need is C/C++ IDE plugin from the Eclipse Tools Project. You can get it here: CDT .

    I would just like to take a moment and say what a great thing the new version 1.2 is.
    Wow, they really have got their act together. Anyone who uses this will find this out
    really quick. And I encourage anyone who agrees with me to help out the development effort.

So, anyhow, all the plugins for eclipse are just pretty much jar files that you put either in the plugins or the features subdirectories. In the case of the CDT however they seem to have put it in the same structure as the actual eclipse project. So, that means you should unzip it into the same directory as you did eclipse. If you are going by my example above that would be your home directory again.

The next time you run eclipse you'll be able to start creating C++ projects. As a matter of fact. I'll lead you right through it right now.

Creating a project

So, go ahead and start up eclipse right now. To create a project you'll go to File->New->Project....


This brings up a dialog for setting up your project.

Project Creation Dialog

If your dialog doesn't look like mine, with the C and C++ options, then your CDT is not installed right. There are two different options with the new 1.2 version, Standard Make C++ Project or Managed Make C++ Project. Select the one that you will need; if you want to maintain your own make file, then select Standard. If you want eclipse to maintain your make file, then select Managed. Since we are just going to do a simple example here, we'll use the managed project. CLICK 'Next >'.

This then bring you to the next screen where you enter your project name and location. Use whatever you like here. If you go with the default location the project will be placed in that workspace subdirectory that I've talked about.

Project Name and Directory

CLICK 'Next >'.

You'll notice that eclipse has figured out that we are going to be using g++ (they think in cygwin). That's ok! Pick your platform and configurations. CLICK 'Next >'.


Go ahead and finish your project setup. You'll be prompted for a perspective switch. I go ahead and click the checkbox and then click 'Yes'. You should probably do so too.

Confirm switch

Creating a File

Close the 'Welcome' view. Let's create a file. Right click on your project in the left hand project viewer. Select New->File

New File

Name your file and click Finish

File name

Once you click 'Finish' the file will be opened in the editor. Lets edit it and see what happens.

Build Complete

You'll notice that eclipse calls the makefile everytime one of your files is saved. Note this if you are going to maintain your own makefiles, be sure to have good dependancies setup so you don't recompile everything just because a file is saved. This is a leftover from being first a java IDE. Not a big deal if you have a well written makefile.

Running your project

Ok, now for the fun stuff

Click on the the little 'Running Man' icon to bring up the Run dialog.


The first time that you do this for a project you'll have to set up what is to be run. Select C/C++ Local and click the 'New' Button.

New Run

You should have something that looks like this.

New Run

Click the Search... button and select the executable that you want to run.

Run What

Once you've done that and saved the changes you've made you'll be able to just click the little 'Running Man' whenever you like. You'll be able to see the output in the console.


Debugging your project

Once you've set up your project to Run correctly it really easy to Debug it using gdb. Just click on the little BUG!Bug icon. You'll be taken to the debug perspective right away. Oh, I almost forgot, you might want to set a breakpoint by double clicking on the bar just to the left of the code before invoking the debugger.

Breakpoint Debugger

ENJOY your experience with eclipse. Just so you know, the same project files that work on windows also work on Linux.


In this section I'll post any questions that come up.

Contact Guurk

I know Guurk is a silly name, but hey, I've played a lot of muds in my time. Contact me here: Guurk

Makefile Tips

I'm not going to pretend that I'm some sort of Guru with makefiles or something, as a matter of fact, far from it. However, there are a couple of little things that I like doing that someone else may find useful.

Finding your files, using rules

I like putting my source files in a subdirectory called 'src'. And likewise for the includes 'include'. My bins go in bin, and so on... Anyhow, because I don't like always adding a new file to my makefile every time I create one, here is how I get my files, thier header dependancies and the rules for them:

Here's how I set up my file lists.

FINDHDR=$(shell find . -name '*.h' | sed "s/\.\///") FINDSRC=$(shell find . -name '*.cpp' | sed "s/\.\///") FINDOBJ=$(shell find . -name '*.cpp' | sed "s/src/bin\/$(TYPE)/" | sed "s/cpp/o/" | sed "s/\.\///") HDRS:=$(FINDHDR) SRCS:=$(FINDSRC) OBJS:=$(FINDOBJ)

Here's how I set up the rule

bin/%.o : src/%.cpp include/%.h $(CPP) $(FLAGS) $(INCLUDES) -c -o $@ $<

SDL type of makefile config helper

The SDL project uses a cool utility that also is used by libxml2 which allows for a makefile to figure out 'dynamically' which flags or libs to use for build with either of those libraries. All they are is a couple of shell scripts that give you at compile time the stuff you need.

When using them in your makefile you can do something like this:

INCLUDES = `sdl-config --cflags` `xml2-config --cflags` `xml++-config --cflags` INCLUDES += `sigc-config --cflags` LIBS = `sdl-config --libs` `xml++-config --libs` `xml2-config --libs` LIBS += `sigc-config --libs`

You'll notice that I have config files for more than just sdl and libxml, I've made a couple for libxml++ and sigc++ as well. The real reason that I like doing this is that I can have specific versions of these files for each of the platforms that I want to build a project on and I don't have to have any platform specific makefiles or makefile logic to handle differences.

Here is what a file looks like, from there you can edit as you wish. Let me re-iterate, this was not my idea, it's not my code, and if you're the person who first did this, I'll put your name on it. I just think it's nifty.

#!/bin/sh prefix=/home/schustej/env exec_prefix=${prefix} exec_prefix_set=no usage="\ Usage: sdl-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]" if test $# -eq 0; then echo "${usage}" 1>&2 exit 1 fi while test $# -gt 0; do case "$1" in -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) optarg= ;; esac case $1 in --prefix=*) prefix=$optarg if test $exec_prefix_set = no ; then exec_prefix=$optarg fi ;; --prefix) echo $prefix ;; --exec-prefix=*) exec_prefix=$optarg exec_prefix_set=yes ;; --exec-prefix) echo $exec_prefix ;; --version) echo 1.2.6 ;; --cflags) echo -I${prefix}/include/SDL -Dmain=SDL_main # The portable way of including SDL is #include "SDL.h" #if test ${prefix}/include != /usr/include ; then # # Handle oddities in Win32 path handling (assumes prefix) # prefix=`echo ${prefix} | sed 's,^//\([A-Z]\),\1:,'` # # includes=-I${prefix}/include #fi #echo $includes -I${prefix}/include/SDL -Dmain=SDL_main ;; --libs) libdirs="-L${exec_prefix}/lib " echo $libdirs -lmingw32 -lSDLmain -lSDL -mwindows ;; --static-libs) # --libs|--static-libs) libdirs="-L${exec_prefix}/lib " echo $libdirs -lmingw32 -lSDLmain -lSDL -mwindows -luser32 -lgdi32 -lwinmm ;; *) echo "${usage}" 1>&2 exit 1 ;; esac shift done

Anyhow, drop me a line if you have some better ideas, or if you like mine.