How to include Box2d with v3.17?

How to include Box2d with v3.17?


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!


Has anyone included Box2D for a Mac project?
On iOS it works for me:

But when i try to compile in Mac, i’ve the same problem:

#include <Box2D/Box2D.h>

'Box2D/Box2D.h' file not found

cc @slackmoehrle


It should work for Mac also.
Please check what that include is added for Mac project settings.


Mac project settings?


Select target Mac and then check project settings


In Build Settings > Header Search Paths i added

I added it in the scheme MyGame-desktop instead of the scheme MyGame-mobile.
Is that what you’re trying to say?
If yes, it doesn’t work.

I’m using CocoaPods in the project. In Podfile i configured only MyGame-mobile.
But box2d is another thing… (no pods).

Sure. It’s a setting problem in my project… i’m sure.


@dimon4eg you could reproduce my error creating a new cocos project.
In HelloWorld.cpp add this line:

#include <Box2D/Box2D.h>

After that, compile it (in mobile). You will see the error.
Then edit Build Settings > Header Search Paths and add

Compile again. It will work.
Now change scheme to MyGame-desktop and compile in your Mac,

You will see the error again.
And… then… how to fix it on desktop…?

EDIT: adding the header search path in MyGame-desktop, clean & re-build, now works in cpp-example but not in my original project… :triumph:


Do you have a Desktop target? Did you add the Box2D path there too?


yep. :confused:


Maybe something with another lib, framework, etc…

Undefined symbols for architecture x86_64:
  "_objc_msgSendSuper2", referenced from:
      -[GLFWWindowDelegate initWithGlfwWindow:] in libcocos2d Mac.a(cocoa_window.m.o)
      -[GLFWContentView initWithGlfwWindow:] in libcocos2d Mac.a(cocoa_window.m.o)
      -[GLFWContentView dealloc] in libcocos2d Mac.a(cocoa_window.m.o)
      -[GLFWContentView updateTrackingAreas] in libcocos2d Mac.a(cocoa_window.m.o)
      -[GLFWApplication sendEvent:] in libcocos2d Mac.a(cocoa_window.m.o)
      -[NSTimerWrapper initWithTimeInterval:callback:] in libcocos2d Mac.a(AudioCache.o)
      -[NSTimerWrapper dealloc] in libcocos2d Mac.a(AudioCache.o)
  "_objc_msgSend_stret", referenced from:
      -[GLFWWindowDelegate windowDidResize:] in libcocos2d Mac.a(cocoa_window.m.o)
      -[GLFWWindowDelegate windowDidMove:] in libcocos2d Mac.a(cocoa_window.m.o)
      __glfwPlatformGetWindowPos in libcocos2d Mac.a(cocoa_window.m.o)
      -[GLFWWindowDelegate windowDidBecomeKey:] in libcocos2d Mac.a(cocoa_window.m.o)
      __glfwPlatformSetCursorMode in libcocos2d Mac.a(cocoa_window.m.o)
      -[GLFWContentView mouseMoved:] in libcocos2d Mac.a(cocoa_window.m.o)
      -[GLFWContentView viewDidChangeBackingProperties] in libcocos2d Mac.a(cocoa_window.m.o)
  "_uncompress", referenced from:
      cocos2d::ZipUtils::inflateCCZBuffer(unsigned char const*, long, unsigned char**) in libcocos2d Mac.a(ZipUtils.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)