Yet another new Iphone user, needs help.

Like most iphone programmers I just recently started programing on the mac, so if I am doing something stupid please let me know.

I am trying to compile the Box2D code into my iphone project. I copied the source and include folders into my project and I am trying to get the HelloWorld example working (To my understanding you can't use dynamic libraries for iphone).

I getting these error when linking

Code:
Building target “2DBox-OpenGLES-test” of project “2DBox-OpenGLES-test” with configuration “Debug” — (7 errors)
       cd /code/TestApps/2DBox-OpenGLES-test
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.0 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.1.sdk -L/code/TestApps/2DBox-OpenGLES-test/build/Debug-iphonesimulator -L/code/TestApps/2DBox-OpenGLES-test/../../Box2D_v2-0-1/Library -L/code/TestApps/2DBox-OpenGLES-test -F/code/TestApps/2DBox-OpenGLES-test/build/Debug-iphonesimulator -filelist /code/TestApps/2DBox-OpenGLES-test/build/2DBox-OpenGLES-test.build/Debug-iphonesimulator/2DBox-OpenGLES-test.build/Objects-normal/i386/2DBox-OpenGLES-test.LinkFileList -mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -o /code/TestApps/2DBox-OpenGLES-test/build/Debug-iphonesimulator/2DBox-OpenGLES-test.app/2DBox-OpenGLES-test
Undefined symbols:
  "b2World::b2World(b2AABB const&, b2Vec2 const&, bool)", referenced from:
      -[My2dBox helloWorld] in My2dBox.o
  "b2Body::CreateShape(b2ShapeDef*)", referenced from:
      -[My2dBox helloWorld] in My2dBox.o
      -[My2dBox helloWorld] in My2dBox.o
  "b2Body::SetMassFromShapes()", referenced from:
      -[My2dBox helloWorld] in My2dBox.o
  "b2World::Step(float, int)", referenced from:
      -[My2dBox helloWorld] in My2dBox.o
  "b2World::~b2World()", referenced from:
      -[My2dBox helloWorld] in My2dBox.o
      -[My2dBox helloWorld] in My2dBox.o
  "b2PolygonDef::SetAsBox(float, float)", referenced from:
      -[My2dBox helloWorld] in My2dBox.o
      -[My2dBox helloWorld] in My2dBox.o
  "b2World::CreateBody(b2BodyDef const*)", referenced from:
      -[My2dBox helloWorld] in My2dBox.o
      -[My2dBox helloWorld] in My2dBox.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
        "b2World::b2World(b2AABB const&, b2Vec2 const&, bool)", referenced from:
            -[My2dBox helloWorld] in My2dBox.o
        "b2Body::CreateShape(b2ShapeDef*)", referenced from:
            -[My2dBox helloWorld] in My2dBox.o
            -[My2dBox helloWorld] in My2dBox.o
        "b2Body::SetMassFromShapes()", referenced from:
            -[My2dBox helloWorld] in My2dBox.o
        "b2World::Step(float, int)", referenced from:
            -[My2dBox helloWorld] in My2dBox.o
        "b2World::~b2World()", referenced from:
            -[My2dBox helloWorld] in My2dBox.o
            -[My2dBox helloWorld] in My2dBox.o
        "b2PolygonDef::SetAsBox(float, float)", referenced from:
            -[My2dBox helloWorld] in My2dBox.o
            -[My2dBox helloWorld] in My2dBox.o
        "b2World::CreateBody(b2BodyDef const*)", referenced from:
            -[My2dBox helloWorld] in My2dBox.o
            -[My2dBox helloWorld] in My2dBox.o
      ld: symbol(s) not found
      collect2: ld returned 1 exit status
Build failed (7 errors)


Does anyone have an idea why I am getting these linking errors?

Thanks for your help.
I'm not positive that this will fix it (I'm just starting iPhone dev myself), but make sure you've added the Box2d files to the "Compile Sources" set under Targets->Your Executable. It's pretty easy to forget, and I don't think it happens automatically.
Wow thanks for quickly responding. You where right about the files not in "Compile Sources". Unfortunately I am now getting 9 linking errors and not 7 😆 .

Because I am shooting in the dark (because of lack of apple / cocoa programming skills), I going to take a step back.

I am now trying to first get a working version of Box2D HelloWorld that doesn't use the dylib, on my mac. Then I will try getting it to work on my iphone.

So I created a new apple cocoa application, added the source files and the include, and it compiles, and links nicely. But when I look at the console to see if everything worked I hit an assert! 🙁

Code:
Assertion failed: (false), function MoveProxy, file /code/NoneIphoneTestApps/Box2DSingleApp/Source/Collision/b2BroadPhase.cpp, line 409.


Now I haven't really look into the issue, and I have homework so I wont spend time on it tonight. but I hoping someone already seen this issue. If not I plan on spend time this weekend on it.

thanks for your help.
Well I solved my own problems..... well one of them 🙂

And because I am a nice guy, and don't want anyone to spend as much time as I did on a simple problem. I am going to tell you how I did it. Right now I only gotten the HelloWorld demo working on the iphone, so other things may not work.

The problem came from b2Math.h line 63.
I change this line to a bunch of "if" statements to check if the values were NaN or infinity, because for some reason iphone doesn't have this function. And this was returning incorrect, I think I am not sure about this, if any one smarter then me could tell me what the issue was that would be sweet.

First I create a static lib project and moved over all the Box2D code. Then I made these changes, to b2Math.h

Old code
line 23:
Code:
#include <math.h>


line 63:
Code:
return finite(x) != 0;


Change to the
Code:
#include <cmath.h>

Code:
return std::isfinite(x) != 0;


Then I added the .a file to my HelloWorld Box2D iphone project. Compiled to the device and "BAM" it worked!

NOTE: If you are going to run your application through the simulator then you can/have to use a dylib (you will have to make changes to b2Math.h though). I couldn't get my .a file to work for some reason, in the simulator. If anyone has any ideas please let me know.

I have one last question that I think I already know the answer too. The zlib license let you use static libraries without having to give out the source code. Is this correct?

Thanks for the physics engine and the help.
evanchri wrote:
Well I solved my own problems..... well one of them 🙂


Hi Evanchri,

would it be possible that you share the code of your iPhone "Hello World"? Especially the XCode project definition file would be very interesting. I am trying to get it working for my project too and get so many errors that I don't know where to start 🙁

Thanks.
Ok, I just had to read the posts more accurate 🙂

I will sum up the steps that lead me to a working version:

1. In my iPhone project I switched to "Targets -> <Project>"
2. With a right click on the project name I have choosen "Add -> Existing Files" and choose the "Source" and "Include" folders in Box2D
3. I applied the changes to the source code as described in a previous post to get rid of the errors
4. I renamed the file where I want to use the Box2D from "<filename>.m" to "<filename>.mm"
5. I added a #include "Box2D.h" and the HelloWorld example sourcecode. It worked!

Thanks for the help and the great framework.
Could someone send me the X-Code-Project. I couldn't get it to run. I am not sure what I am doing wrong 😕 here.

Thanx alot.

Max

Original thread: https://box2d.org/forum/viewtopic.php?t=1513