在 SceneView.h 中:
#ifndef ProtoAlpha_SceneView_h
#define ProtoAlpha_SceneView_h
#include "cocos2d.h"
#include "SceneModel.h"
#include "SceneController.h"
#include "CharacterModel.h"
#include "CharacterDerived.h"
USING_NS_CC;
class SceneView : public CCLayer {
private:
static SceneModel* sceneModel;
static SceneView* sceneViewLayer;
static SceneController* sceneControllerLayer;
CharacterModel* t1;
CharacterModel* t2;
CCSprite* t1Sprite;
// scheduled Update
void update(float dt);
在 SceneView.ccp 中:
CCScene* SceneView::scene() {
// 'scene' is an autorelease object
CCScene* scene = CCScene::create();
// 'layer' is an autorelease object
sceneModel = new SceneModel;
sceneViewLayer = SceneView::create();
sceneControllerLayer = new SceneController(*sceneModel->buffer);
// add layer as a child to scene
scene->addChild(sceneViewLayer);
scene->addChild(sceneControllerLayer);
// return the scene
return scene;
}
和错误:
Undefined symbols for architecture i386:
"SceneView::sceneModel", referenced from:
SceneView::scene() in SceneView.o
SceneView::update(float) in SceneView.o
"SceneView::sceneViewLayer", referenced from:
SceneView::scene() in SceneView.o
"SceneView::sceneControllerLayer", referenced from:
SceneView::scene() in SceneView.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如果我要注释掉 .ccp 文件中的代码,链接器错误就会消失,因此不太可能是编译源错误。
通过一些搜索,我发现一些人提到此代码的符号可能有些隐藏,我希望了解这里实际发生了什么。