我有一个奇怪的链接器问题。我的代码看起来像这样:
double given_amount = self.modelController.levelCompleteRewardAmount;
swrve_currency_given(swrve, (CFStringRef)@"currencyName", given_amount);
我将这段代码放在两个不同的地方:在 objective-c 和 objective-c++ 文件中。它在 Objective-C 领域编译良好,但 swrve_currency_given() 函数在我的 WGController.mm 文件中导致以下内容:
Undefined symbols for architecture armv7:
"swrve_currency_given(Swrve*, __CFString const*, double)", referenced from:
-[WGController giveTheUserSomeCashForPlayingThisLevel] in WGController.o
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
我不完全确定此错误是否与 Obj-C 与 C++ 相关,但它感觉 是这样。我的理论是它可能认为它是 Obj-C 类上的一个函数? “swrve”代码是第 3 方代码,一个 .h 和 .c 文件,我是这样导入的:
#import "swrve.h"
感谢任何帮助! 谢谢
最佳答案
您可能需要将函数原型(prototype)括起来:
#if defined __cplusplus
extern "C" {
#endif
void swrve_currency_given (...whatever goes here...);
#if defined __cplusplus
};
#endif
这告诉编译器它是一个 C 函数而不是 C++ 函数。
关于objective-c - 从 Objective-C++ 调用 C-Function 的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9334650/