Objective-c 中的外部 C 函数

发布于 2024-07-24 23:11:09 字数 284 浏览 2 评论 0原文

我开发 iPhone 应用程序,更新到 sdk 3.0 后,链接时出现 CFWriteStreamCreateWithFTPURL 错误。 这是我调用来获取错误的代码。

streamInfo.writeStream = CFWriteStreamCreateWithFTPURL(NULL, urlRefWrite);

我有一个想法,可以使用 extern "C" 来解决它,但是在谷歌搜索之后,我还没有找到解决我的问题的方法。 有任何想法吗?

提前致谢

i develop iPhone apps, and after updating to sdk 3.0, I get an error on CFWriteStreamCreateWithFTPURL while linking. This is the code I call to get the error.

streamInfo.writeStream = CFWriteStreamCreateWithFTPURL(NULL, urlRefWrite);

I have an idea that it can be solved using extern "C", but after having googled it, I have not found the solution to my problem. Any ideas?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半步萧音过轻尘 2024-07-31 23:11:09

extern "C" 可能可以解决问题。 我可以通过在实现和头文件声明周围执行类似的操作来编译和链接 C 函数。 这是一个简单的例子:



#if __cplusplus
extern "C" {
#endif

/// converts a degree value to radians
double DegreesToRadians(double degrees);

/// converts radian value to degrees
double RadiansToDegrees(double radians);


#if __cplusplus
}   // Extern C
#endif


实现文件:


#import "Math.h"

#if __cplusplus
extern "C" {
#endif


double DegreesToRadians(double degrees) {return degrees * M_PI / 180;};
double RadiansToDegrees(double radians) {return radians * 180/M_PI;};


#if __cplusplus
} //Extern C
#endif

extern "C" may do the trick. I'm able to get C functions to compile and link by doing something like this both around the implementation and header file declaration. Here's a simple example:



#if __cplusplus
extern "C" {
#endif

/// converts a degree value to radians
double DegreesToRadians(double degrees);

/// converts radian value to degrees
double RadiansToDegrees(double radians);


#if __cplusplus
}   // Extern C
#endif


Implementation file:


#import "Math.h"

#if __cplusplus
extern "C" {
#endif


double DegreesToRadians(double degrees) {return degrees * M_PI / 180;};
double RadiansToDegrees(double radians) {return radians * 180/M_PI;};


#if __cplusplus
} //Extern C
#endif

南汐寒笙箫 2024-07-31 23:11:09

您永远不必在 Objective-C 项目中使用 extern "C"。 这是因为 Objective-C 是 C 的严格超集。

You should never have to use extern "C" in an Objective-C project. This is because Objective-C is a strict superset of C.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文