Trouble with ofxChipmunk and Codeblocks

I’m currently moving a project from Xcode into Codeblocks and my last stumbling point appears to be something with ofxChipmunk. For the sake of keeping things very simple to identify the problem, I’ve made a test project using emptyExample. I can include ofxChipmunk.h in the testApp.h and everything compiles just fine. The trouble comes when I attempt to call any of the chipmunk methods (ie cpvlength() or any other).

This is all it takes to causes the error:

void testApp::setup(){  
    cpVect v1;  
    v1.x = 5;  
    v1.y = 2;  
    float length = cpvlength(v1);  

If I comment out the line that calls cpvlength, everything builds just fine. However, if I leave that line in there, I get the following error:

obj\release\src\testApp.o:testApp.cpp:(.text+0x3e)||undefined reference to `_cpvlength’|

If I try to call the setup() method of an ofxChipmunk object, I get a ton more of these kinds of errors for every chipmunk method it is calling. I had no problems at all getting ofxChipmunk building and working in an Xcode project so I don’t understand what is happening here.

There is a header in Chipmunk called “chipmunk_ffi.h” that has a bunch of stuff like this for a bunch of chipmunk functions:

// Create non static inlined copies of Chipmunk functions, useful for working with dynamic FFIs  
// This file should only be included in chipmunk.c  
#define MAKE_REF(name) __typeof__(name) *_##name = name  
MAKE_REF(cpv); // makes a variable named _cpv that contains the function pointer for cpv()  

But as far as I can tell, its never included by anything and I don’t have any idea what all that means anyway.

Can anyone tell me what I’m missing here? Assuming that the answer is pretty simple.

you have to initialize chipmunk first.
check the bottom of ofxChipmunk.h - there should be some initialization code.


Hey Theo,

I’m afraid that isn’t the problem here. the code above is just a simplified example. My actual project works fine in Xcode on OS X and calls ofxChipmunk’s setup() which calls the init before it does anything else. That same project has these kind of errors described above when moved into codeblocks.

I tried adding the line ofxChipmunk::init() to the above code and it yields this error:

obj\release\src\testApp.o:testApp.cpp:(.text+0x12)||undefined reference to `_cpInitChipmunk’|

Looks like you are missing the actual chipmunk library ( .c files ) from your project. ofxChipmunk is a wrapper to chipmunk - so double check you have the source code for that or a codeblocks compiled version of the library. The xcode chipmunk .a won’t work in a Windows Codeblocks project for obvious reasons.

I have a PC version of chipmunk - but won’t be able to get to it for a couple of days.


I have all the .c files included in your addon in the project. I was actually getting compilation errors from them before because I’d forgotten to add the header search paths. But after I got that all cleared up, I could compile with no errors, even including “chipmunk.h” in testApp didn’t cause any problems. The problems begin only when functions from the library are called. Seems really strange.

Do I need a .a file for compiled for codeblocks in addition to those source files? Should I not have the actual chipmunk source in the project and just point the compiler to it’s search paths?

Codeblocks… Ugh.

Ok… looks like I’ve got it working now.

Seems like a ridiculous thing for me to have overlooked in hindsight, but I had to download the .c source files of Chipmunk and include them in the project.

Another little thing I had to do was use the following compiler flag:


This needs to get pasted into your project’s Build Options, under the “Other options” tab. Without this, the compiler will complain about all the i variables being declared inside of for loops.

Btw, I’ve made some additions to ofxChipmunk that make it really simple to add mouse interaction and respond to collision events. I hope to clean it up and post it soon.


Ok… one more Code::blocks and Chipmunk problem.

In my application, I create some static wall objects around the world space. I think that something in the way the compiler is set up is not agreeing with this line:

body = cpBodyNew(INFINITY, INFINITY);  

Maybe the INFINITY constant isn’t getting set properly because of some compiler setting? Anyway, the problem happens at runtime once I start letting Chipmunk update:

Aborting due to Chipmunk error: Unsolvable collision or constraint.
Failed condition: value != 0.0

If I just create the body with a really big value for the mass (and still use INFINITY for the second argument), everything seems to work well enough. Still, I wonder what the problem is with INFINITY in Codeblocks (this is code that has never been a problem in Xcode).

ahh thats the NDEBUG flag not being set.

at the top of chipmunk.h

#define NDEBUG

should fix it.
otherwise you get asserts everywhere.

also be careful making static bodies which have mass.
and likewise free bodies with no mass.


for some reasons chipmunk on CB is way more of a pain than in xcode - no idea why but all sort of weird bugs pop up which don’t happen in xcode.

ps to spare you some headaches - be careful of SSE optimization flags and fast math flags with the chipmunk library on windows. / CB.

yep #define NDEBUG solved that last problem.

spending a few hours in Code::blocks makes me so much more thankful for Xcode.

thanks for helping me get to the light at the end of the tunnel.

Unrelated question… is there some kind of compiler flag I can set somewhere so that my printf()'s don’t make it out to the console that starts with OF windows executables? Or maybe I just need to hunt them all down.

hey no problem.

One thing you can do is hide the console all together.
I think if you right click on the project in the side bar and open the settings panel you can change the application type to a gui application ( i think thats what its called ). This hides the console all together - you have to rebuild the project for the changes to work though.