0

I'm mixing C++ with ObjectiveC for a Cocos2d (objective-C) and Box2D (C++) project.

I have the following C++ class:

class ActorListener : public b2ContactListener
{ 
    public :
    const b2Body* Owner;

    ActorListener(const b2Body* owner);
    ~ActorListener();

    virtual void BeginContact(b2Contact* contact);
    virtual void EndContact(b2Contact* contact);
    virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);    
    virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
};

Which I try to initialise with:

(in header)

ActorListener* Listener;

(in mm file)

Listener = new ActorListener(Body); 

I get the error:

Undefined symbols for architecture i386:
  "vtable for ActorListener", referenced from:
      ActorListener::ActorListener(b2Body const*)in ActorListener.o
      ActorListener::ActorListener(b2Body const*)in ActorListener.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

2 Answers 2

4

The vtable is emitted in the same file as the first virtual function of the class. In this case, ~ActorListener() is the first virtual method, because b2ContactListener::~b2ContactListener() is virtual. Did you remember to define ActorListener::~ActorListener() somewhere?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. There is a very descriptive message when you forget a regular virtual (like the ones I had lower) but that very general one if you forgot destructor.
0

The trick is to get XCode to use g++ to do the linking. You can force this either by including a C++ source file on the link line -- even a fake, essentially empty one -- or (I think) by explicitly linking with /usr/lib/libstdc++.6.dylib .

2 Comments

Can you explain how to do this in more detail? (noob at xcode)
Literally just including a source file named fake.cpp in your project containing #define FOO 1 will do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.