1
\$\begingroup\$

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...

Thanks!!!

\$\endgroup\$

4 Answers 4

1
\$\begingroup\$

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"

\$\endgroup\$
1
  • \$\begingroup\$ Hi! Thanks for answering. That's what I did :P I thought it would be painful but it wasn't (Y). \$\endgroup\$
    – Axort
    Commented Mar 14, 2012 at 16:17
0
\$\begingroup\$

If you followed the procexdure in here: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:lesson_1._install_test

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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... \$\endgroup\$
    – Axort
    Commented Feb 29, 2012 at 19:12
0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ I'll try that as my last resort. That should work. \$\endgroup\$
    – Axort
    Commented Feb 29, 2012 at 23:44
  • \$\begingroup\$ Any issue, ask :) \$\endgroup\$
    – Rudy_TM
    Commented Feb 29, 2012 at 23:45
-2
\$\begingroup\$

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ What's "cmack"? This is quite vague. Why do you think this would solve the problem? \$\endgroup\$
    – Anko
    Commented May 16, 2014 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .