Enable Box2D on XCode on Existing Project

Hi,

I copy the HelloCpp project and create my game for android, now im trying to compile with xcode.

Everything is compiling OK, i have added on “include search path” property on xcode the path to “external” directory that contains box2d headers, but when i try compile i got error on linking:

Ld /Users/paulo/Library/Developer/Xcode/DerivedData/DownBlocks-ehmercbdqnskfrbihpczgdnbajxo/Build/Products/Debug-iphonesimulator/DownBlocks.app/DownBlocks normal i386
    cd /Users/paulo/Pessoal/workspaces/cpp/downblocks/projects/DownBlocks/proj.ios
    setenv IPHONEOS_DEPLOYMENT_TARGET 4.0
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk -L/Users/paulo/Library/Developer/Xcode/DerivedData/DownBlocks-ehmercbdqnskfrbihpczgdnbajxo/Build/Products/Debug-iphonesimulator -L/Users/paulo/Pessoal/workspaces/cpp/downblocks/projects/DownBlocks/proj.ios/../../../cocos2dx -F/Users/paulo/Library/Developer/Xcode/DerivedData/DownBlocks-ehmercbdqnskfrbihpczgdnbajxo/Build/Products/Debug-iphonesimulator -filelist /Users/paulo/Library/Developer/Xcode/DerivedData/DownBlocks-ehmercbdqnskfrbihpczgdnbajxo/Build/Intermediates/DownBlocks.build/Debug-iphonesimulator/DownBlocks.build/Objects-normal/i386/DownBlocks.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=4.0 /Users/paulo/Library/Developer/Xcode/DerivedData/DownBlocks-ehmercbdqnskfrbihpczgdnbajxo/Build/Products/Debug-iphonesimulator/libcocos2dx.a -framework Foundation -framework UIKit -framework CoreGraphics -framework OpenGLES -lxml2 -lz -framework QuartzCore -o /Users/paulo/Library/Developer/Xcode/DerivedData/DownBlocks-ehmercbdqnskfrbihpczgdnbajxo/Build/Products/Debug-iphonesimulator/DownBlocks.app/DownBlocks

Undefined symbols for architecture i386:
  "b2EdgeShape::Set(b2Vec2 const&, b2Vec2 const&)", referenced from:
      HelloWorld::createBox2DWorld() in HelloWorldScene.o
  "b2MouseJoint::SetTarget(b2Vec2 const&)", referenced from:
      PhysicsSprite::ccTouchMoved(cocos2d::CCTouch*, cocos2d::CCEvent*) in PhysicsSprite.o
  "b2PolygonShape::Set(b2Vec2 const*, int)", referenced from:
      HelloWorld::createBox2DBodyForSprite(cocos2d::CCSprite*, int, b2Vec2*) in HelloWorldScene.o
  "b2PolygonShape::SetAsBox(float, float)", referenced from:
      HelloWorld::init() in HelloWorldScene.o
      HelloWorld::createBox2DBodyForSprite(cocos2d::CCSprite*, int, b2Vec2*) in HelloWorldScene.o
  "b2Body::SetTransform(b2Vec2 const&, float)", referenced from:
      HelloWorld::updateBox2DWorld(float) in HelloWorldScene.o
  "b2Body::CreateFixture(b2FixtureDef const*)", referenced from:
      HelloWorld::init() in HelloWorldScene.o
      HelloWorld::createBox2DBodyForSprite(cocos2d::CCSprite*, int, b2Vec2*) in HelloWorldScene.o
  "b2Body::CreateFixture(b2Shape const*, float)", referenced from:
      HelloWorld::createBox2DWorld() in HelloWorldScene.o
  "b2World::CreateBody(b2BodyDef const*)", referenced from:
      HelloWorld::init() in HelloWorldScene.o
      HelloWorld::createBox2DWorld() in HelloWorldScene.o
      HelloWorld::createBox2DBodyForSprite(cocos2d::CCSprite*, int, b2Vec2*) in HelloWorldScene.o
  "b2World::CreateJoint(b2JointDef const*)", referenced from:
      PhysicsSprite::ccTouchBegan(cocos2d::CCTouch*, cocos2d::CCEvent*) in PhysicsSprite.o
  "b2World::DestroyBody(b2Body*)", referenced from:
      HelloWorld::updateBox2DWorld(float) in HelloWorldScene.o
  "b2World::DestroyJoint(b2Joint*)", referenced from:
      PhysicsSprite::ccTouchEnded(cocos2d::CCTouch*, cocos2d::CCEvent*) in PhysicsSprite.o
      PhysicsSprite::ccTouchCancelled(cocos2d::CCTouch*, cocos2d::CCEvent*) in PhysicsSprite.o
  "b2World::SetAllowSleeping(bool)", referenced from:
      HelloWorld::createBox2DWorld() in HelloWorldScene.o
  "b2World::SetContactListener(b2ContactListener*)", referenced from:
      HelloWorld::createBox2DWorld() in HelloWorldScene.o
  "b2World::Step(float, int, int)", referenced from:
      HelloWorld::updateBox2DWorld(float) in HelloWorldScene.o
  "b2World::b2World(b2Vec2 const&)", referenced from:
      HelloWorld::createBox2DWorld() in HelloWorldScene.o
  "vtable for b2EdgeShape", referenced from:
      b2EdgeShape::b2EdgeShape() in HelloWorldScene.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for b2PolygonShape", referenced from:
      b2PolygonShape::b2PolygonShape() in HelloWorldScene.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Can anyone help me?

Can anyone help me please?

Hi,
I, to insert the Box2D src in my project, I had “drag&drop” the source code inside xcode project! There is another way?

bye!

Paulo Coutinho wrote:

Hi,
>
I copy the HelloCpp project and create my game for android, now im trying to compile with xcode.
>
Everything is compiling OK, i have added on “include search path” property on xcode the path to “external” directory that contains box2d headers, but when i try compile i got error on linking:
>
[…]
>
Can anyone help me?

The Box2D source already is especified in “include headers path”, this is not the problem.

The problem is when linking.

ok!

Are you sure, that XCode has compiled the Box2d sources? check on project settings/Build phases/Compiles sources…

Stefano

Paulo Coutinho wrote:

Hi,
>
I copy the HelloCpp project and create my game for android, now im trying to compile with xcode.
>
Everything is compiling OK, i have added on “include search path” property on xcode the path to “external” directory that contains box2d headers, but when i try compile i got error on linking:
>
[…]
>
Can anyone help me?

Hi Stefano,

You are correct man, i forgot that we need do it in xcode, now it is working.

Very thanks.

oh! yeah!

good work!

Paulo Coutinho wrote:

Hi,
>
I copy the HelloCpp project and create my game for android, now im trying to compile with xcode.
>
Everything is compiling OK, i have added on “include search path” property on xcode the path to “external” directory that contains box2d headers, but when i try compile i got error on linking:
>
[…]
>
Can anyone help me?