【发布时间】:2015-01-08 12:27:49
【问题描述】:
长版:我希望在 C++ 中实现我的应用程序模型,并在 Cocos2d-x 使用 C++ 的任何地方使用此模型,以便:(1) 我知道它具有相同版本的 C++ (2) 时机成熟时,我可以从 Cocos2d-x 中删除我的应用程序模型。我从 Mac OS X 和 iOS 开始,在开始这个项目之前,我会确保一切都可以编译。在 iOS 上,一切正常。在 Mac 上,基本的 C++ 每次都会给我一个链接器错误!
短版开始:我有一个 C++ 类,如下所示:
class GetInteger {
public:
static int GetInt();
};
到目前为止一切都很好,所以让我继续定义我的超级复杂的静态函数:
int GetInteger::GetInt()
{
return 5;
}
好的,这是基本的 C++,我现在要继续使用我的超级复杂函数:
"include "GetInteger.h"
...
int theInt = GetInteger::GetInt();
...
事情仍然非常简单,事实上,当我使用适用于 iOS 的 Cocos2d-x 项目的标准设置在 Xcode for iOS 中编译这段代码时,一切都可以正常工作。但是当我尝试在 Mac 上运行此代码时,会出现以下错误:
Undefined symbols for architecture x86_64:
"GetInteger::GetInt()", referenced from:
AppDelegate::applicationDidFinishLaunching() in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是为什么?我该如何解决这个问题?
这是我来自ZippyShare的项目文件。
【问题讨论】:
标签: c++ ios xcode macos cocos2d-x