Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extern C functions in Objective-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

like image 729
Hans Espen Avatar asked Feb 20 '26 11:02

Hans Espen


2 Answers

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

like image 199
Tom Avatar answered Feb 22 '26 02:02

Tom


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

like image 21
Jonathan Sterling Avatar answered Feb 22 '26 00:02

Jonathan Sterling