Friday, June 24, 2011

Box2D and Eclipse

Well, after about an hour and a half of effort, scouring the Internet and some elbow grease (heh) I *FINALLY* have got the Box2D testbed to compile using Eclipse on my Windows 7 x64 box.  It's not all that straightforward.  Here's an outline of the steps you'll need to take:

1) Install Eclipse (duh?) and the CDT (C Development Tools)
2) Install MinGW & related gcc/g++
3) Install & build GLUT for Win32
4) Download Box2D source
5) Install CMAKE, tweak some of the output and have it create your build file

Details for those steps:

1) Install Eclipse and the CDT.  You can grab Eclipse from  I'm personally using the Helios release.  I grabbed the Java edition (a while ago, actually).  To install the CDT for C development support, open up Eclipse and go to Help > Install New Software...  Set the "Work with:" drop-down to all sites and enter "CDT" as the filter text.  Eventually you'll be presented with things to install.  I selected everything.  Easy peasy.

2) Install MinGW.  Go to and download and execute the installer.  In the installation options, select pre-packaged catalogues and when queried, select C++ compiler, MSYS Basic System, and MinGW Developer Toolkit. Easy peasy (again).

3) Install GLUT for Win32 w/MinGW support.  I followed the instructions up on which is actually a reference to  There are instructions there for downloading and building glut-3.7.6 from src files.  Follow steps 2 through 7 on that site.  You'll need to perform these steps using the MSYS Shell prompt installed as part of step 2.  If things work out correctly, you'll see the gear test demo.

The next thing is to be able to build from Eclipse.  Ensure your environment path references the /bin directory of the MinGW installation.  Create a new C++ project in Eclipse.  Set it up as an Empty project and select MinGW GCC from the Toolchain list in the right pane.   This initially did not come up for me until I added the f:\mingw\bin path to my environment.  Anyway, name the project "GLUTDemo".

Go to and follow steps 5c through 6c.  This will create a project containing Demo.cpp that will verify you can create a GLUT based project and that it works.

4) This is really simple.  Just hit the Box2d website at to grab the latest and greatest source.  I'm running v2.1.2.  Extract that to some directory on your machine.

5) Box2d requires that you have Cmake installed.  Grab that from and install it.  Next, you need to use it to configure the build attributes for Box2D AND specify that you want it to create stuff for Eclipse.  Open a cmd.exe prompt.  Yes, a cmd.exe prompt -- not the MSYS sh.exe.  Navigate to the Box2D Build sub-directory.  From here, enter the following:
cmake -G"Eclipse CDT4 - MinGW Makefiles" -D CMAKE_BUILD_TYPE=Debug ..
You can now go into Eclipse and import the resulting project.  The build will kick off and eventually fail when it gets to the link stage of the TestBed.  Don't fret.   Open up Testbed\CmakeFiles\Testbed.dir\link.txt and add the following to the end of the last line:

-lwinmm -static-libgcc -static-libstdc++
This clears up a few problems: undefined references to joygetdevcaps & some time functions, and also libgcc_s_dw2-1.dll / libstdc++-6.dll not being found when trying to start the resulting .exe.

Right-click on the project and tell it to build.  This time, a testbed.exe should be created and you can happily run it.


No comments:

Post a Comment