Objective C: Inline function - symbol not found

血红的双手。 提交于 2019-11-30 17:49:56

You should add the static specifier to your inline function definition if the function is intended for use only in the same translation unit (internal linkage),

static inline int add(int x, int y) {return x+y;}
int s = add(1, 2);

If you omit static in the example above (in Debug configuration, where no optimization is performed and no inlining is carried out), the linker will exit with error complaining _add is referenced but Symbol(s) not found.

In C99, an inline function declaration without any storage specifier will not generate an actual callable function body so the linker gives an error when it needs one.

If your inline function may be used by other modules, it's more complicated. A common practice is to include the inline function definition (without extern) in the header file and include exactly one prototype declaration with extern in exactly one module.

A good article explaining inline functions in C99: http://www.drdobbs.com/184401540

just add FOUNDATION_EXPORT to function on the header (.h). Remember import Foundation/Foundation.h (OS X) or UIKit/UIKit.h (ios).

Example:

//.h
#import <UIKit/UIKit.h>

FOUNDATION_EXPORT inline NSString * myInlineFunction(void);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!