Search code examples
c++classconstructorbox2dcocos2d-x

Xcode Linker Error Cocos2d-x Box2D CContactListener constructor undefined


I'm trying to get Box2D running with my Cocos2d-x project. I'm adding collision detection but I get a linker error Undefined symbols for architecture i386: "CContactListener::CContactListener()", referenced from: HelloWorld::init() in HelloWorldScene.o

I've tried several things and researched for a few days but can't figure it out. Any help wold be great. Here's some code pieces

HelloWorldScene.h

 CContactListener *_contactListener; //Variable declared and #include "ContactListener.h" is present at the top

HelloWorldScene.cpp

_contactListener = new CContactListener(); //This line gets the error
_world->SetContactListener(_contactListener);

ContactListener.h

class CContactListener : public b2ContactListener {

public:


CContactListener();
~CContactListener();
std::vector<ContactData>_contacts;
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);

};

ContactListener.cpp

#include "ContactListener.h"

CContactListener::CContactListener(): _contacts() 
{
}

CContactListener::~CContactListener() 
{
}
//...other functions

Solution

  • CContactListener.cpp was not added the the target build in Xcode. I simply checked the target box for my project in the File Inspector for the .ccp file. Easy fix.