views:

2221

answers:

3

Hi, 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 Hans Espen

A: 

Hans,

I'm trying to accomplish an FTP upload on the iPhone OS 3.0. I'm having issues since the only sample (CFFTPSample) from Apple is in "C". Would you be willing to post the code you got working? If you prefer, you can email me @ jsutton at circlepix d.o.t com.

Thanks, Juan

+1  A: 

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

Jonathan Sterling
+1  A: 

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

#import <CoreFoundation/CoreFoundation.h>

/// 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

Tom