2013-03-07 166 views
0

我试图让我的Cocos2d-x项目运行Box2D。在HelloWorldScene.o的HelloWorld ::的init()Xcode链接器错误Cocos2d-x Box2D CContactListener构造函数undefined

我试过几个:我添加碰撞检测,但我得到一个链接错误i386硬件架构 未定义的符号:“CContactListener :: CContactListener()”,从引用事情和研究了几天,但无法弄清楚。任何帮助都会很棒。 下面是一些代码片段

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 
+1

这看起来很奇怪:CContactListener :: CContactListener():_contacts()在C++中是否合法?我只看到它用于不是对象的类的成员变量(除了将它们设置为零)。 – LearnCocos2D 2013-03-07 18:14:46

+0

每个实现联系人侦听器的例子都有它,所以我会认为它没问题。 – 2013-03-07 19:59:21

回答

1

CContactListener.cpp未添加在Xcode的目标构建。我只是在文件检查器中为.ccp文件检查了我的项目的目标框。轻松修复。