5

我经历过 Objective-C++ 的一些奇怪行为。我有一个 Objective-C++ 类,它在方法体中调用一个经典的 C 函数。但是链接器找不到 C 函数。

我在这里描述了这个问题: Xcode print symbol not found for my C function which used in Objective-C method body

我通过将 Objective-C++ 类更改为 Objective-C 类解决了这个问题,但问题仍然存在。它是否禁止在 Objective-C++ 类中调用 C 函数?

4

1 回答 1

10

您需要确保声明了 C 函数

extern "C"

在适当的 .h 文件中。

这样做的常见方法是:

//
// 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
于 2010-02-06T16:08:16.713 回答