How to include Box2d with v3.17?

How to include Box2d with v3.17?


I don’t do anything to obtain Box2d. In 3.13.1, all I had to do was type:

#include <Box2d/Box2d.h>

And I could use Box2d without any problem. Between 3.13.1 and 3.17, something has changed in how Box2d is included with cocos2d, so this is no longer possible.

I think when something like this is changed, documentation should be added in the gift book, so it’s easy to figure out how to do things like this.


So it means between 3.16 and 3.17 something was removed, so we cannot just directly use “include”.


@slackmoehrle in 2d-x 3.17, project has added the box2d header search path in build setting, so we only need to add the box2d .a file in Build Phases, and add the library search path in build setting, maybe there is something wrong in the hearder search paths.
The box2d’s head file is in the location “path/to/2d-x/external/Box2D/include/Box2D/Box2D.h”, two “Box2D” here, xcode only finds the first “Box2D” path, missing the second. <Box2D/Box2D.h> is not working.


Any suggestion?


We are having the same issue. Any suggestion?


ok, let me start looking at this more.


And make sure to compile with CC_ENABLE_BOX2D_INTEGRATION=1 (Windows)


I tried that, but it doesn’t help Xcode find Box2d. It still won’t compile since it can’t find the headers properly


Try adding this line as the image, maybe this will help:


I create an empty project with 3.17, and add box2D include path in setting like this:

but I still can not find the correct header file path in xcode:


v3.16 box2d

// Solve position constraints
bool positionSolved = false;
for (int32 i = 0; i < step.positionIterations; ++i)
	bool contactsOkay = contactSolver.SolvePositionConstraints();

	bool jointsOkay = true;
	for (int32 j = 0; j < m_jointCount; ++j)
		bool jointOkay = m_joints[i]->SolvePositionConstraints(solverData);  // here! line 317
		jointsOkay = jointsOkay && jointOkay;

line 317 => bool jointOkay = m_joints[ j ]->SolvePositionConstraints(solverData);
change i to j, it will be fine,I think.


Did someone solve this issue?
I’ve the same problem. include <Box2d/Box2d.h> not work in 3.17.
I included box2d .a file in Build Phrases but i continue with the problem…


You having same issue for both iOS and Android?


For the moment I’m trying to compile 3.17 only in iOS. But when I can compile it on iOS, I’ll try on Android


It would be really great if some cocos2d-x developer explained how to do this.


Adding the search path mentioned above worked for us


Thanks @vkreal2
I included $(PROJECT_DIR)/../cocos2d/external/Box2D/include in Build Settings > Header Search Paths and now it works.


Thank you! It works!


I’m now experiencing this issue as well with version 3.17 and it seems that the Box2d headers were removed from the /external/ folder. The only Box2d file I can find in the cocos project is /Frameworks/libbox2d.a. So the previous suggestion to add a search path to a header which no longer exists cannot work.

chipmunk-Box2D Gideros framework-cocos2d-x recreations

Just download Cocos2dx v3.17 from the download section of this website. there is a “/external/Box2D” folder. 100%!

I added two lines in

LOCAL_C_INCLUDES += $(LOCAL_PATH)/…/…/…/cocos2d/external/Box2D/include


it’s the same for xcode projects. add box2d paths to “Header Search Paths” + If you cant find the Box2d folder in your project navigator… you had also to add the folder to your project)

Enable Box2D in your Project:
xcode: CC_ENABLE_BOX2D_INTEGRATION=1 (search for “Preprocessor Macros” under Build Settings)

In your Code use it like : #include "Box2D/Box2D.h"

it works!