【发布时间】:2014-04-19 14:23:59
【问题描述】:
我在 XCode 5 上关注 iOS 的 Cocos2D-X 教程,讲师从创建一堆类和头文件开始。其中有一个名为“Utils.h”的头文件,其中包含一些静态函数
class Utils
{
public:
static Game* gameLayer();
static HUD* hudLayer();
static cocos2d::CCLayer* layerWithTag(int tag);
static cocos2d::CCSize s();
static cocos2d::CCAnimate* getAnimationWithFrames(int from, int to);
static void scaleSprite(cocos2d::CCSprite * sprite);
static float getScale();
static void setScale(float s);
static float getArtScaleFactor();
static void setArtScaleFactor(int s);
};
s() 函数在 Utils.cpp 中定义为 return CCDirector::sharedDirector()->getWinSize();
现在,问题是:在我的主菜单场景中调用 s() 函数时(例如 Utils::s().width),我收到此错误“链接器命令失败,退出代码为 1(使用 -v 查看调用) ”和“未找到架构 i386 的符号”。但是,当我从 Utils.cpp 中删除了s() 函数定义并只是在头文件的类中添加了该函数时,它就变成了
//Utils.h
class Utils
{
public:
.......
static cocos2d::CCSize s()
{
return CCDirector::sharedDirector()->getWinSize();
}
......
编译没有错误...
为什么函数在cpp文件而不是头文件中时会出现此错误?我知道我的问题已经解决了,但这让我发疯了
谢谢! :)
编辑:我认为这是给定的,但更清楚的是,在主菜单场景中,我包含了 Utils.h 而不是 Utils.cpp
【问题讨论】:
-
有该教程的链接吗?谢谢
标签: c++ ios xcode linker cocos2d-x