实例化 C++ 时遇到问题目标 C 的类别
我将 C++ 与 ObjectiveC 混合用于 Cocos2d (objective-C) 和 Box2D (C++) 项目。
我有以下 C++ 类:
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);
};
我尝试使用以下内容进行初始化:(
在标头中)
ActorListener* Listener;
(在 mm 文件中)
Listener = new ActorListener(Body);
我收到错误:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
诀窍是让 XCode 使用 g++ 进行链接。您可以通过在链接行上包含 C++ 源文件(即使是假的、本质上是空的文件)或(我认为)通过显式链接 /usr/lib/libstdc++.6.dylib 来强制执行此操作。
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 .
vtable 与类的第一个虚拟函数在同一文件中发出。在本例中,
~ActorListener()
是第一个虚拟方法,因为b2ContactListener::~b2ContactListener()
是虚拟的。您是否记得在某处定义ActorListener::~ActorListener()
?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, becauseb2ContactListener::~b2ContactListener()
is virtual. Did you remember to defineActorListener::~ActorListener()
somewhere?