在Objective-c中

时间:2023-02-06 19:58:38

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.

我开发了iPhone应用程序,在更新到sdk 3.0后,在链接时,我在CFWriteStreamCreateWithFTPURL上有一个错误。这是我调用来获取错误的代码。

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?

我有个想法,可以用extern "C"解决问题,但在谷歌上搜索之后,我并没有找到解决问题的方法。什么好主意吗?

Thanks in advance

谢谢提前

2 个解决方案

#1


8  

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:

外面的“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


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

#2


3  

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

您不应该在Objective-C项目中使用extern“C”。这是因为Objective-C是C的严格超集。

#1


8  

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:

外面的“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


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

#2


3  

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

您不应该在Objective-C项目中使用extern“C”。这是因为Objective-C是C的严格超集。