Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem including box2D to my cocos2d project. I've tried different ways to do it with no success. This is what I've done:

  • I downloaded Box2D (Box2D_v2.2.1) to my project directory.
  • Dragged the Box2D directory (which includes -> /Box2D.h, /Collision, /Common, /Dynamics, /Rope) to my Xcode project (from Finder to Xcode)
  • Then I added #include "Box2D.h" to my .h file and got many errors... Here is where I started my research :P
  • I went to Project Settings and edited the attribute Header Search Paths (contained in the Search Paths section) specifying the path of Box2D. At this point, I builded the project and I got less errors.
  • After that, I renamed my .m file to .mm (I think this is because Box2D is written in C++ and with this, the compiler can treat it as it is). Still got errors.
  • Then I tried changing the attribute Always Search User Paths (contained in Project Settings -> Search Paths) from YES to NO. Still got errors.
  • As my last option I tried changing the attribute Compile Sources As (contained in Project Settings -> LLVM GCC 4.2 - Language) from According to File Type to Objective-C++.

By now I'm frustrated xD. I have 203 errors and most of them are in the .h files contained in the Box2d engine.

b2Timer.h - Expected '=', ',', ';', 'asm' or 'attribute' before 'b2Timer'

b2Distance.h - Expected specifier-qualifier-list before 'b2DistanceProxy'

b2Math.h - Cfloat: No such file or directory

And so on...


share|improve this question
up vote 1 down vote accepted

You need to use the Cocos2D binding provided, never the Box2DLibrary as-is. If you have already starter your project without it the best thing I can recommend is either start a new template with Box2D included this time and import all the code (less painful than expected) or hardlinking "box2d.h" already included in the cocos2d folder "cocos2d-iphone\external\Box2d"

share|improve this answer
Hi! Thanks for answering. That's what I did :P I thought it would be painful but it wasn't (Y). – Axort Mar 14 '12 at 16:17

If you followed the procexdure in here:

and installed the cocos2d, it would have added cocos2d-box2d and cocos2d-chipmunk templates that comes in new project window of xcode.

By creating projects this way, all the libraries are integrated and setup by default.

share|improve this answer
Hi! Thanks for answering... Well, I have those templates but I didn't create my project that way. I created a project with the first template that appears (cocos2d only). Now I want to incorporate Box2D to my project... – Axort Feb 29 '12 at 19:12

If all its wrong, you may create a new project directly from box2D, and migrate everything. It's the last thing I can think of. You have made everything already so this is a last resort. It might work.

share|improve this answer
I'll try that as my last resort. That should work. – Axort Feb 29 '12 at 23:44
Any issue, ask :) – Rudy_TM Feb 29 '12 at 23:45

You need brew to install cmack, then use it to install Box2D.

share|improve this answer
What's "cmack"? This is quite vague. Why do you think this would solve the problem? – Anko May 16 '14 at 15:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.