how to include Box2d in cocos2d-x project?

503 views Asked by At

In cocos2d-x v3.13.1, if I wanted to use just Box2d (not the integrated chipmunk physics), all I had to do was:

#include <Box2d/Box2d.h>

But after upgrading to v3.17, it doesn't work. Instead there is an error saying:

Lexical or preprocessor issue: file not found

How do I include Box2d with minimum fuss ? My project is cross platform (iOS and Android), so rather than having to have separate steps for each platform, I am looking for something as simple as what I used to do with 3.13 - just typing #include etc...

1

There are 1 answers

0
abc On

The following instructions are for Android only.

First of all don't use #include <> for non standard library includes, rather use simple quotations.

To answer your question, the reason why it's not recognized is because the linker doesn't know where to find the Box2d header files.

Simply open up your Android.mk file which should be located in YourProjectRoot/proj.android/app/jni/Android.mk.

In the top of the file add this line:

$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/external/Box2D/include)

Now everything should work it's that simple :)

I'm assuming if you are using Box2d you won't want to use Chipmunk so make sure to disable it by setting the -DCC_ENABLE_CHIPMUNK_INTEGRATION flag equal to 0. You can find this flag in the corresponding Application.mk file.