【问题标题】:Does it prohibited calling classic C function from Objective-C++ class method body?是否禁止从 Objective-C++ 类方法体中调用经典 C 函数?
【发布时间】:2010-02-06 15:59:55
【问题描述】:

我经历了 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 函数?

【问题讨论】:

    标签: c function linker objective-c++


    【解决方案1】:

    您需要确保已声明 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
    

    【讨论】:

    • 哇,太棒了,这拯救了我的一天
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 2010-11-06
    • 2023-03-29
    • 2012-12-12
    • 1970-01-01
    • 2013-12-23
    相关资源
    最近更新 更多