Adding Box2D to an iPhone project

Just thought I would share the following info on adding Box2D to your own iPhone projects

- Drag the Box2D folder into your project (select "Copy items into destination group's folder (if needed)" to make a copy of the files)
- Change File Type from c.objc to cpp.objcpp (Use command-select your .m source files, then right click->Get Info->General->File Type)
- Select Project->Project Settings->Build (Use search)
--> Always Search User Paths: YES
--> Header Search Paths: "$(SRCROOT)" (put a tick next to recursive)
--> Compile for Thumb: NO (this is because thumb is slow when using floating point)
--> Other C Flags / Other C++ Flags: -DTARGET_OS_IPHONE
- You may get some errors about malloc. This just means you have to cast explicitly.

Eg.

Code: Select all

value = malloc(size);


If the error is "Invalid conversion from 'void*' to 'SomeType*', then change it to..

Code: Select all

value = (SomeType*) malloc(size);


EDIT: Sorry this should probably be moved to "Build Issues".
Just wanted to mention that you could also just use Cocos2d for iphone which has a version of Box2d bundled within it and works quite well.

Regards,
Q
how to run bridge sample using cocos2d inbuilt box2d??

Original thread: https://box2d.org/forum/viewtopic.php?t=4360