How to include Box2d with v3.17?

I do not want to use the integrated physics, but create my own worlds and manipulate them separately.

In v3.13.1, to use Box2d, i simply had to do:

#include <Box2d/Box2d.h>

And everything seemed to work. I could create b2World etc.

I upgraded to 3.17, and it seems that there is an error when I try:

#include <Box2d/Box2d.h>

How do I include Box2d ?

3 Likes

i got the same error, i tryed everything but not fix it, and i used box2d in version 3.16 instead of 3.17 at last.

1 Like

How are you obtaining Box2D?

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.

1 Like

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.

1 Like

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:

2 Likes

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


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

v3.16 box2d
…\external\Box2D\Dynamics\b2Island.cpp

    ......
// Solve position constraints
timer.Reset();
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.

Hi,
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

1 Like

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

1 Like