ObjectiveChipmunk - undef symbol for ChipmunkObjectFlatten

Discuss any Chipmunk bugs here.
Post Reply
mikelaurence
Posts: 10
Joined: Thu Sep 15, 2011 12:09 am
Contact:

ObjectiveChipmunk - undef symbol for ChipmunkObjectFlatten

Post by mikelaurence »

I just grabbed Chipmunk and have been wrapping my head around the demo Objective Chipmunk code (using the simulator .a build).

Everything was going smoothly and building until I added the ChipmunkObjectFlatten command to my object. Now I get a "Undefined symbol for architecture i386" error via the linker.

Is there an issue with the .a file, or did I miss a step somewhere?

Thanks very much for the help - can't wait to finish up my test and get to the real deep physicky stuff! :D
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: ObjectiveChipmunk - undef symbol for ChipmunkObjectFlatt

Post by slembcke »

That's weird. That's the only symbol it says is missing? That would be really weird. My best guesses in that case:
  • You missed an import statement.
  • Are you sure it was spelled correctly
  • You are using it in a way that makes the compiler think it's not actually a function?

Posting some of the code might help I guess? Are there any warnings or other errors? Where did you get the lib from?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mikelaurence
Posts: 10
Joined: Thu Sep 15, 2011 12:09 am
Contact:

Re: ObjectiveChipmunk - undef symbol for ChipmunkObjectFlatt

Post by mikelaurence »

Got the code from the Chipmunk 6.0.0 zipfile on the main site (BTW ObjectiveChipmunk isn't in the 6.0.1 archive...)

My code is pretty boilerplate - I'm using the suggested "chipmunkObjects as a synthesized property" method:

Code: Select all

// as properties in header
ChipmunkBody *body;
ChipmunkShape *shape;
NSSet *chipmunkObjects;

// in implementation
shape = [ChipmunkPolyShape boxWithBody:body width:size.width height:size.height];
shape.elasticity = 0.3f;
shape.friction = 0.3f;
shape.data = self;
  
if (chipmunkObjects) [chipmunkObjects release];
chipmunkObjects = [ChipmunkObjectFlatten(body, shape, nil) retain];
I'm importing ObjectiveChipmunk.h via the class's header file, and it compiles, so it's aware that ChipmunkObjectFlatten should exist. It just doesn't work in the linkage, which would seem to indicate that it's not finding it in the pre-built simulator .a object file? I think I'm calling it correctly... maybe you can tell from the code I put above.

Full error:
Undefined symbols for architecture i386:
"ChipmunkObjectFlatten(objc_object*, ...)", referenced from:
-[GameObject setShapeAsBox:] in GameObject.o
-[GameObject setShapeAsCircle:] in GameObject.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

I'm using a iPhone 4.3 simulator target.
slembcke wrote:That's weird. That's the only symbol it says is missing? That would be really weird. My best guesses in that case:
  • You missed an import statement.
  • Are you sure it was spelled correctly
  • You are using it in a way that makes the compiler think it's not actually a function?

Posting some of the code might help I guess? Are there any warnings or other errors? Where did you get the lib from?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: ObjectiveChipmunk - undef symbol for ChipmunkObjectFlatt

Post by slembcke »

O_o That is bizarre that that is the only missing symbol.

My last guess, are you using Objective-C++? That C function prototype is not wrapped in an extern C block, which is the only thing I can think of that would cause the function to be the only thing not found.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mikelaurence
Posts: 10
Joined: Thu Sep 15, 2011 12:09 am
Contact:

Re: ObjectiveChipmunk - undef symbol for ChipmunkObjectFlatt

Post by mikelaurence »

That could be it - I am still using obj-c++ (in the process of converting from Box2D C++ code.)

I suppose I won't need obj-c++ now, but there are other projects where I'm using physics and other c++ libs. Any way to get that function rolling with obj-c++?
slembcke wrote:O_o That is bizarre that that is the only missing symbol.

My last guess, are you using Objective-C++? That C function prototype is not wrapped in an extern C block, which is the only thing I can think of that would cause the function to be the only thing not found.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: ObjectiveChipmunk - undef symbol for ChipmunkObjectFlatt

Post by slembcke »

Aha. That is definitely the problem. C functions are linked differently than C++ functions because the latter can be overloaded or templated.

Try this:

Code: Select all

extern "C" {
#import "ObjectiveChipmunk.h"
}
That lets the C++ compiler know that any functions defined in the {} are actually C functions and not C++ ones.

It might complain because the Chipmunk headers also have an extern "C" block in them. If that's the case, just put it around that function in the header. I actually think that is the only C function in the Objective-Chipmunk API.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mikelaurence
Posts: 10
Joined: Thu Sep 15, 2011 12:09 am
Contact:

Re: ObjectiveChipmunk - undef symbol for ChipmunkObjectFlatt

Post by mikelaurence »

There were some cpVect functions that were complaining when I wrapped my main ObjectiveChipmunk.h import with "extern C", so I moved the ChipmunkObjectFlatten definition into its own ChipmunkC.h file and wrapped that - now everything is compiling and physicking around.

Thanks for the support! I'm pumped to get started with some new, non-C++ physics :D
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests