Chr*_*ill 26 objective-c objective-c++
我有一个奇怪的链接器问题.我的代码看起来像这样:
double given_amount = self.modelController.levelCompleteRewardAmount;
swrve_currency_given(swrve, (CFStringRef)@"currencyName", given_amount);
Run Code Online (Sandbox Code Playgroud)
我在两个不同的地方有这个代码:在objective-c和objective-c ++文件中.它在objective-C land中编译很好,但是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
Run Code Online (Sandbox Code Playgroud)
我不完全确定这个错误是否与Obj-C与C++有关,但感觉就像它.我的理论是它可能认为它是Obj-C类的一个函数?'swrve'代码是第三方代码,一个.h和.c文件,我像这样导入:
#import "swrve.h"
任何帮助表示赞赏!谢谢
use*_*321 46
您可能需要使用以下函数包围函数原型:
#if defined __cplusplus
extern "C" {
#endif
void swrve_currency_given (...whatever goes here...);
#if defined __cplusplus
};
#endif
Run Code Online (Sandbox Code Playgroud)
这告诉编译器它是C函数而不是C++函数.
如果你在c ++文件中使用c函数.你应该使用extern "c"{}.在.h文件中
#ifdef __cplusplus
extern "C" {
#endif
swrve_currency_given(parameter1, parameter2, parameter3);// a c function
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
extern"C"意味着被C++编译器识别,并通知编译器所提到的函数是(或将)以C风格编译的.
如果您要链接到编译为C代码的库.使用
extern "C" {
#include "c_only_header.h"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11955 次 |
| 最近记录: |