内联函数"未定义符号"错误

use*_*301 24 c compiler-errors inline objective-c linker-errors

我想写一个内联函数,但是我收到一个错误.我该如何解决?

错误信息:

Undefined symbols for architecture i386:
  "_XYInRect", referenced from:
      -[BeginAnimation ccTouchesEnded:withEvent:] in BeginAnimation.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

码:

CGPoint location = CGPointMake(60, 350);

if (XYInRect(location, 53, 338, 263, 369)) {

}

inline BOOL XYInRect(CGPoint location, float MixX, float MixY, float MaxX ,float MaxY){
    if (location.x >MixX && location.y >MixY && location.x <MaxX && location.y <MaxY) {
        return YES;
    } else {
        return NO;

    }
}
Run Code Online (Sandbox Code Playgroud)

Chr*_*oph 36

Clang 默认为C99而不是GNU sematics,这意味着raw 和inline两者都不同.static inlineextern inline

特别是,raw inline表示函数仍然具有外部链接,但内联定义不提供外部链接(您需要extern inline它).

这意味着您需要extern在不同的翻译单元中使用其他定义,否则链接将失败.但是,你可能正在寻找static inline.