Cocos2d iphone Apple Mach-O链接器(Id)错误问题

Cocos2d iphone Apple Mach-O链接器(Id)错误问题,cocos2d-iphone,box2d,linker-errors,box2d-iphone,Cocos2d Iphone,Box2d,Linker Errors,Box2d Iphone,我已经读了很多关于这个问题的帖子,但我没有发现任何特别有用的东西。当两个精灵使用联系人侦听器相遇时,我尝试创建一个焊接接头。我不断得到以下错误: Apple Mach-O Linker (Id) Error "_touchingBodies", referenced from: SubcContactListener::BeginContact(b2Contact*) in SubcContactListener.o ld: symbol(s) not found for architectur

我已经读了很多关于这个问题的帖子,但我没有发现任何特别有用的东西。当两个精灵使用联系人侦听器相遇时,我尝试创建一个焊接接头。我不断得到以下错误:

Apple Mach-O Linker (Id) Error
"_touchingBodies", referenced from:
SubcContactListener::BeginContact(b2Contact*) in SubcContactListener.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我的联系人。 subcontactlistener.h:

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Box2D.h"
#import <vector>
typedef std::pair<b2Body*, b2Body*> bodyPair;
typedef std::vector<bodyPair> thingsThatTouched;

extern thingsThatTouched touchingBodies;

class SubcContactListener : public b2ContactListener    {

public:

    void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
};
我补充说:

 thingsThatTouched touchingBodies;
到HelloWorldLayer.h接口

最后,在HelloWorldLayer.mm的勾选方法中(在时间步之后):

b2WeldJointDef-weldJointDef;
b2WeldJoint*焊接接头;
对于(int i=0;iGetWorldCenter());
weldJointDef.collideConnected=false;
焊接接头=(b2WeldJoint*)世界->创建接头(&weldJointDef);
}
触摸物体。清除();
请帮忙,我已经做了一段时间了

extern thingsThatTouched touchingBodies;
这些外部变量必须在别处定义为静态C变量,而不是实例变量

考虑到更好的设计,我建议放弃extern变量,而是通过HelloWorldLayer添加一个Singleton接口来访问TouchBody

然后您就可以从任何地方访问它:

[HelloWorldLayer sharedWorldLayer].touchingBodies;
extern thingsThatTouched touchingBodies;
[HelloWorldLayer sharedWorldLayer].touchingBodies;