How to set up the demo project in Code::Blocks

Official forum for the Chipmunk2D Physics Library.
Post Reply
bennysce
Posts: 12
Joined: Sat Sep 27, 2008 3:14 am
Contact:

How to set up the demo project in Code::Blocks

Post by bennysce »

I'm using Code::Blocks and I created a similar project to the msvc one in chipmunk's svn. I decided to write down what I did if anyone else is using the same things. It took me 4 hours to get this working :(

This thread helped me with some things: http://www.slembcke.net/forums/viewtopic.php?f=1&t=250 Thanks!

Hope it helps! And let me know if something is better done another way or if something isn't clear. I might include images and format it better if demanded.


CREATING THE CHIPMUNK DEMO PROJECT IN CODE::BLOCKS
========================================================

DOWNLOAD AND INSTALL PREREQUISITES (If you haven't already)

Install Codeblocks and GLUT for this to work.

1. Install Code::Blocks if you haven't done so. For windows get it here: http://www.codeblocks.org/downloads/binaries

2. Make sure you get the version with MinGW included so you have a GCC compiler.

3. Start the installer and follow the instructions

4. Make sure glut.h and glut32.lib are in codeblocks MinGW/include and lib folders or elsewhere they can be found.


CREATING THE PROJECT

1. When Codeblocks is started, create a new project as a GLUT project. File->New->Project..

2. Choose GLUT Project. Click the Go-button.

3. In the wizard. Click next (check the box if you don't want to see that screen anymore).

4. Name your project, specify where to install and hit next again.

5. Point out where you have your glut files (include and lib containing glut.h and glut32.lib respectively). Click next.

6. Here the GCC compiler should already be selected in the drop-down list if you downloaded the right codeblocksversion. Just click Finish.

7. A default main.cpp was created when the project was created. go ahead and remove it by right-clicking on it and choose "remove file from project". We'll use the main.c as starting point in the chipmunk source later.


GETTING THE CHIPMUNK SOURCE FILES

I got the source from the SVN repository like this:

1. Download and install TortoiseSVN. http://tortoisesvn.tigris.org/

2. Create an empty folder somewhere to put the chipmunk files. Open the folder and right-click and choose SVN Checkout...

3. enter http://chipmunk-physics.googlecode.com/svn/trunk/ as "URL of repository". More info: http://code.google.com/p/chipmunk-physi ... e/checkout

4. The folder you created should be preselected below. Click OK. All chipmunk files should be downloaded to your folder. Close the tortoisesvn windows.


ADDING THEM TO THE CODEBLOCKS PROJECT

1. Copy the Demo and src folders from the svn folder to your project folder.

2. In codeblocks, right-click your project in the Management listview to the left and choose "Add files recursively..."

3. Find your project folder and click OK.

4. A list of files to be included appears. Make sure ONLY .h and .c files are checked. Click OK

5. A new window appears. Click Select All so the source is included for both debug and release builds. Click OK.


CONFIGURING THE PROJECT

If you build now, chipmunk.h won't be found.

1. To correct this right-click your project again in the management view and this time choose Build options... NOTE: make SURE your project name is selected, not release or debug as you would have to place the following things in both configurations otherwise.

2. Click the "Search directories" tab and click Add. Find the chipmunk src folder and click OK.

If we build now, it will complain about a for-loop declaration outside C99 mode. To get around this:

3. Enter build options again and make sure the compiler settings tab is selected then choose the Other options tab. Enter "-std=c99" without quotes in the box here. Click OK.

If we build again it complains about M_PI not being defined.

4. Next we need 2 defines for a clean build. M_PI and GLUT_BUILDING_LIB (I got some missing GLUT undefined functions otherwise. there's probably a better way to do this..)

Either define them in main.c like so:

#define Enter M_PI=3.141592653589
#define GLUT_BUILDING_LIB

or enter build options yet again and under compiler settings click the #defines tab. add:

GLUT_BUILDING_LIB;M_PI=3.141592653589


BUILD AND RUN

Finally build the project and enjoy the demos!
SysCoder
Posts: 3
Joined: Mon Jan 18, 2010 1:41 am
Contact:

Re: How to set up the demo project in Code::Blocks

Post by SysCoder »

Thanks!!!

I have been trying to compile with MinGW for awhile! Before I was trying to do it from the command line.

I was able to compile, but when I tried to link things did not work for me. I am a C# programmer (Wanna be expert C++ programmer). So I am not an expert with the linking and so forth.

(Error I was getting)
C:\Users\Marcellus\Documents\PalmPreApplicationsDev\ChipmunkLatest\Chipmunk-5.0.0\src>gcc -static -o libchipmunk.a *.o
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(libcmain.o):(.text+0xab):
undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status

I would still like to know how to do it from the command line. But now I got it to run in the Code::Blocks, I might can figure out the command line way.


p.s.
I got a little confused at this point
"5. Point out where you have your glut files (include and lib containing glut.h and glut32.lib respectively). Click next."
Maybe replace "glut files" to "glut folders include and lib"

I had to include the following in some of the files to get it to work.


(Maybe just one for this)
#define GLUT_DISABLE_ATEXIT_HACK

#include "gl/glut.h"


(And several for this)
#define M_PI 3.141592653589
#define M_PI_2 3.141592653589





[EDIT] I feel that this should be pinned!!! So others can find it easily
___________________________
[url]http:\\www.digilogic.com[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How to set up the demo project in Code::Blocks

Post by slembcke »

SysCoder wrote:gcc -static -o libchipmunk.a *.o
You can't build a static library that way. What you are telling GCC to do there is to make a statically linked executable, and an executable needs a main() or in the case of Windows a WinMain() function.

I'm not sure about MinGW, but to make a static lib on other platforms you do something like this:
ar rcs libChipmunk.a *.a
Where did you have to define the M_PI constants? (M_PI_2 is actually M_PI/2.0)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
SysCoder
Posts: 3
Joined: Mon Jan 18, 2010 1:41 am
Contact:

Re: How to set up the demo project in Code::Blocks

Post by SysCoder »

Thanks for responding! I used what you said and I was able to compile from the command line and reference from my source code.

The files I added M_PI_2 to are:
Demo\ChipmunkDemo.c|30|#define M_PI_2 3.141592653589|
Demo\Joints.c|31|#define M_PI_2 3.141592653589|
Demo\Plink.c|31|#define M_PI_2 3.141592653589|
Demo\Pump.c|31|#define M_PI_2 3.141592653589|
Demo\PyramidTopple.c|31|#define M_PI_2 3.141592653589|
Demo\Query.c|34|#define M_PI_2 3.141592653589|
Demo\TheoJansen.c|37|#define M_PI_2 3.141592653589|
Demo\drawSpace.c|46|#define M_PI_2 3.141592653589|

Thanks for making Chipmunk. I thought about making my own physics for my game, but I thought I probably waste time and not learn as much as if I used someone else and learn from theirs.

[edit] Oh yeah... for anybody that comes across this post. This also helped me http://www.adp-gmbh.ch/cpp/gcc/create_lib.html
___________________________
[url]http:\\www.digilogic.com[/url]
Rawlyn
Posts: 33
Joined: Mon Mar 30, 2009 3:06 am
Contact:

Re: How to set up the demo project in Code::Blocks

Post by Rawlyn »

SysCoder wrote:Thanks for making Chipmunk. I thought about making my own physics for my game, but I thought I probably waste time and not learn as much as if I used someone else and learn from theirs.
I reckon you'd learn more if you wrote your own physics engine - but it's a damn sight quicker and easier to use one that's already been written! ;)
[url=http://www.xboxlc.com/profile/Rawlyn][img]http://www.xboxlc.com/cards/sig/black/Rawlyn.jpg[/img][/url]
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests