更新时间:2022-12-10 13:49:39
不,那里使用纯C没什么问题。通常,源文件将被命名为 *。c
而不是 *。m
,但是将 *。c
重命名为 *。m
应该不会引起错误。
No, there is no problem with using pure C. Usually, the source files will be named *.c
instead of *.m
, but renaming *.c
to *.m
shouldn't cause errors.
但是,有一个线索:
Operation(MyStruct)$ c $从
x
Operation(MyStruct)
referenced fromx
引用的c>如果链接器知道函数的类型参数,这是因为您正在从C ++代码中调用函数。您将必须在标题中放入 extern C {...}
,如下所示:
If the linker knows the type of the function parameters, it's because you're calling the function from C++ code. You will have to put extern "C" { ... }
in the header as follows:
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
float n;
} MyStruct;
float Operation(MyStruct ms);
#ifdef __cplusplus
}
#endif
如果您的项目中没有任何C ++(包括Objective-C ++ *。mm
文件),那么这不是您的问题。
If you don't have any C++ in your project (including Objective-C++ *.mm
files), then this isn't your problem.