Linking Box2D with Xcode?

Sorry if this is a really obvious answer, but how do I link Box2D?

I’ve tried the normal download of Box2D, and also with it installed through Homebrew, and I can have the header files found, but when I try to compile my program I get the errors

Undefined symbols for architecture i386:
  "b2World::b2World(b2Vec2 const&)", referenced from:
      ofApp::setup() in ofApp.o
  "b2World::~b2World()", referenced from:
      ofApp::setup() in ofApp.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I’m new to using c++ libraries and stuff, so I’m at a bit of a loss for what to do.

I’d recommend using

If you downloaded box2d and compiled it, it probably compiled as 64 bit by default.

Homebrew is also 64bit by default. openFrameworks is not yet 64 bit compatible (but will be soon).

ld: symbol(s) not found for architecture i386 means that the libraries did not contain any 32 bit code, leading me to believe that it was only 64bit.

Alright, that makes sense why it wasn’t working.

I added the Box2D addon to the addons folder, do I just link the ofxBox2d folder to the project settings to use it?

I’m not exactly sure what you mean by linking the the ofxBox2d folder – I’d recommend using the Project Generator (it’s included in the openFrameworks distribution) to create an xcode project with the ofxBox2D addon. After copying the ofxBox2d folder to the openFrameworks/addons/ folder open project generator, name your project, click to the addons section to include ofxBox2D and then generate it.

I meant like is there any way of using ofxBox2d without needing to create a new project?

Sure, it is possible to do it manually, but it is a little more complicated. You should be able to drag the addon into the project tree and then you’ll need to add the addon’s headers to the header search path.

To see an example of that, look at one of the ofxBox2D project settings. Here’s where you find them in Xcode: