Page 1 of 1

Trouble Using Chipmunk as a Static Library on Mac

Posted: Wed Feb 27, 2013 2:28 pm
by zizmax
Hey guys, I did a bit of looking here for an answer to my question with no luck. I hope this hasn't been answered before. I did see some post saying TO use Chipmunk as a static library but I didn't see anything on HOW to actually use the static library. I was able to successfully run the "macstatic.command" script and the directory was generated but I cannot figure out how to use these files. I am trying to get the example Hello World program found in the FAQ working. Here is what I have done so far: I made a folder called Chipmunk including all of the script's output and the helloworld.c source, I modified the code to point directly to the headers like this:

Code: Select all

#include </Users/***MyName***/Desktop/Chipmunk/chipmunk.h>
, and I am trying to compile with this in Terminal:

Code: Select all

cc helloworld.c
After entering that many errors come up:

Undefined symbols for architecture x86_64:
"_cpSpaceNew", referenced from:
_main in ccBkVTqw.o
"_cpSegmentShapeNew", referenced from:
_main in ccBkVTqw.o

The list of "Undefined symbols" is quite extensive (too many to include here probably.) What I'm asking is if anyone knows how to abolish these errors and get the code compiling correctly. I apologize in advance if this has an obvious answer or if this has been answered already.
Thank you, zizmax.

Re: Trouble Using Chipmunk as a Static Library on Mac

Posted: Wed Feb 27, 2013 2:58 pm
by slembcke
The errors are because you didn't tell it to link the code in the libChipmunk.a file. You just need to add that to your build command. Because it's a static library, you just list it as an input file instead of using the -l option.

So:
cc myfile.c /path/to/libChipmunk.a

Also, if you use the -I option, you can define a header search path:
cc -I/path/to/Chipmunk-Mac myfile.c /path/to/libChipmunk.a

Then in the code you can just do:
#include "chipmunk.h"

instead of needing to have a giant absolute path.

Re: Trouble Using Chipmunk as a Static Library on Mac

Posted: Wed Feb 27, 2013 3:05 pm
by zizmax
Thank you so much for the quick reply! This worked perfectly! Now the code is compiling totally fine. :) Just a suggestion, if it's possible it may be a good idea to mention including the path to the ".a" file in the FAQ.

Thanks again, zizmax.

Re: Trouble Using Chipmunk as a Static Library on Mac

Posted: Wed Feb 27, 2013 3:47 pm
by slembcke
Well, if you are using Xcode, that just one of those things that it magically knows and takes care of for you. When building anything on the command line, there are a lot of little things like that you need to know. There are also a half dozen other ways you could link it in if you wanted to.