simple step by step: how do I include Box2d in my project?

Compiling, Linking, and Debugging C++ Box2D
dylpickler
Posts: 4
Joined: Sun Nov 06, 2011 3:40 pm

simple step by step: how do I include Box2d in my project?

Postby dylpickler » Sun Nov 06, 2011 3:50 pm

language: c++
environment: xCode 4
version of Box2D: 2.2.1

I just need some idea of how to add box2d to my current project…
I've tried everything I can think of: adding the source files to my project, making a libBox2d.a file and adding that… I've also tried adding the Box2d directory to my "header search paths" but everything I do just results in header files that can't be found…

i think I'm missing something very simple. so just a simple step by step would be amazing… everything else I've found on the internet is for different versions of either Xcode or box2d and none of them work… I don't know what else to do. been pulling my hair out for days.

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: simple step by step: how do I include Box2d in my projec

Postby Erin Catto » Sun Nov 06, 2011 7:02 pm

I think that version of Box2D comes with an Xcode project file. You can see how that is set up.

irresistible force
Posts: 1988
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: simple step by step: how do I include Box2d in my projec

Postby irresistible force » Sun Nov 06, 2011 9:45 pm

It could just be that your header search paths setting is one level off... Box2D source is set up to be included as:

#include <Box2D/Box2D.h>

...so your header search path should specify the folder above where the Box2D.h file is, not the actual folder that contains it.
http://www.iforce2d.net/b2dtut/setup-ios

dylpickler
Posts: 4
Joined: Sun Nov 06, 2011 3:40 pm

Re: simple step by step: how do I include Box2d in my projec

Postby dylpickler » Mon Nov 07, 2011 10:02 pm

Erin Catto wrote:I think that version of Box2D comes with an Xcode project file. You can see how that is set up.

I found the Xcode project file, I just have no idea what to do with it. i mean, it runs and everything, but how does that help me exactly? how do i get the box2d library in my own project?
thanks,
Last edited by dylpickler on Mon Nov 07, 2011 10:11 pm, edited 1 time in total.

dylpickler
Posts: 4
Joined: Sun Nov 06, 2011 3:40 pm

Re: simple step by step: how do I include Box2d in my projec

Postby dylpickler » Mon Nov 07, 2011 10:39 pm

irresistible force wrote:It could just be that your header search paths setting is one level off... Box2D source is set up to be included as:

#include <Box2D/Box2D.h>

...so your header search path should specify the folder above where the Box2D.h file is, not the actual folder that contains it.
http://www.iforce2d.net/b2dtut/setup-ios


ok. I changed my #include to the one you said above and changed my header search path from "Box2D" to "./". the code compiles now and no longer gives me all those linker errors! woot! :D. but now xCode is giving me a "Apple Mach-O Linker (Id) Warning" it says "ld: warning: directory not found for option '-L/Users/dylpickler/Programs/The Deep Project/The Deep Project/Box2D'"

I also tried "../" as my header search path and got the same result then I tried changing my include back to #include "Box2D.h" and it still runs, it just gives that warning do you have any idea what that warning means? i seem to be able to access box2d functions and use them now, so I'm not sure what its complaining about. thanks so much

dylpickler
Posts: 4
Joined: Sun Nov 06, 2011 3:40 pm

Re: simple step by step: how do I include Box2d in my projec

Postby dylpickler » Mon Nov 07, 2011 10:50 pm

nevermind… turns out the error was left over from one of my previous attempts to fix this issue.
thanks for all your help and the quick replies folks.

if anyone else is reading this and trying to learn from my mistakes and they want a step by step, heres what I ended up doing: I put the Box2D folder (the one with the Box2D.h file and all the source files in sub folders) not in the folder with all my source files for my project, but the folder above that, the one with my Xcode project file in it. Inside Xcode I clicked "Add files to project" and chose that same box2d folder. then under project build settings, I changed "always search user paths" to yes and I double clicked on "user header search paths" and put in

Code: Select all

./
as my path and checked the recursive box.

wsurferdude
Posts: 1
Joined: Thu Nov 24, 2011 7:09 pm

Re: simple step by step: how do I include Box2d in my projec

Postby wsurferdude » Thu Nov 24, 2011 7:22 pm

I've found that if you create a project using a cocos2d template and you include the box2d source, the build search paths in 'Build Settings' are filled in with 'YES' for 'Always Search Users Paths' and 'User Header Search Paths' always contain your project directory name and /libs... Example: If your projects directory name is 'MyBox2D' then the 'User Header Search Paths should read: 'MyBox2D/libs'. I've found that this works every time for me when I include cocos2D Box2D source in XCode 4.2 using iOS 5. 8-)


Return to “Build Issues”



Who is online

Users browsing this forum: No registered users and 2 guests