views:

243

answers:

1

I have experienced some strange behavior of Objective-C++. I have an Objective-C++ class, and it calls a classic C function in a method body. But linker cannot find the C function.

I described the problem here: http://stackoverflow.com/questions/2213589/xcode-print-symbol-not-found-for-my-c-function-which-used-in-objective-c-method-b/2213671#2213671

I solved the problem by changing Objective-C++ class to Objective-C class, but the question is still remained. Does it prohibited calling C function in Objective-C++ class?

+3  A: 

You need to make sure that the C functions are declared

extern "C"

in the appropriate .h file.

The common way of doing this is:

//
// foo.h
//

#ifndef __FOO_H__
#define __FOO_H__

#ifdef __cplusplus
extern "C" {
#endif

// ... your interface here - normal C function declarations etc ...

#ifdef __cplusplus
}
#endif

#endif
Paul R
It works! Thanks.
Eonil