Search code examples
c++xcodegame-enginegame-physicsbox2d

Trouble Adding Box2D to Xcode (12.4) project


I have a project that I can open up with Xcode 12.4 (using cmake -G Xcode ..) and I want to be able use Box2D with it. Like some other people, there seems to be a problem with just running brew install box2d (which installs 2.4.1) and then trying #include <Box2D/Box2D.h>. However, I haven't found much help for more recent versions of Xcode (a lot of the solutions are at least 5 years old) and trying to use Box2D has really been a struggle. Has anybody figured this out with Xcode 12.4 and if so, what are some easy steps to take? Box2D is working just find on my friend's Linux. Thanks

OSX: Big Sur 11.4.1

box2d: 2.4.1

Xcode 12.4

fatal error: 'Box2D/Box2D.h' file not
      found
#include <Box2D/Box2D.h>

I've tried looking for Header Search Paths but I have no idea how to find or adjust such settings in Xcode 12.4.


Solution

  • What works for me, in XCode 12.3 at least, is in XCode's Build Settings for the build target:

    • Add -lBox2D to "Other Linker Flags".
    • Add /usr/local/include (the path to where Box2D's include files got installed) to "Header Search Paths".
    • Add /usr/local/lib (the path to where Box2D's library got installed) to "Library Search Paths".

    If your installation of Box2D is in different locations then of course you'll need to use the locations for your install.