0
我已閱讀了關於此問題的許多帖子,但是我沒有發現任何特別有用的內容。當兩個精靈使用接觸監聽器相遇時,我正在嘗試進行焊接。我不斷收到以下錯誤:Apple Mach-O鏈接器(Id)錯誤問題
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)
這是我的聯繫人偵聽器。 SubcContactListener.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);
};
SubcContactListener.mm:
#import "SubcContactListener.h"
void SubcContactListener:: BeginContact(b2Contact *contact) {
touchingBodies.push_back(std::make_pair(contact->GetFixtureA()->GetBody(), contact->GetFixtureB()->GetBody()));
}
我加入:
thingsThatTouched touchingBodies;
到HelloWorldLayer.h接口。
最後,在HelloWorldLayer.mm(時間步長之後)的刻度方法:
b2WeldJointDef weldJointDef;
b2WeldJoint *weldJoint;
for (int i = 0; i < touchingBodies.size(); i++) {
b2Body* bodyA = touchingBodies[i].first;
b2Body* bodyB = touchingBodies[i].second;
weldJointDef.Initialize(bodyA, bodyB, bodyA->GetWorldCenter());
weldJointDef.collideConnected = false;
weldJoint = (b2WeldJoint*)world->CreateJoint(&weldJointDef);
}
touchingBodies.clear();
請幫幫忙,我一直盯着它一段時間。