内联函数“未定义符号”错误

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

错误信息:

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) 

码:

 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; } } 

Clang 默认为C99而不是GNU sematics ,这意味着原始inline不同于static inlineextern inline

特别是,原始inline意味着该函数仍然具有外部链接,但内联定义不提供外部链接(您需要extern inline )。

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

我认为XYInRect()在使用之前需要知道。 在调用之前将函数定义移动到文件中的某个位置。

也建议使用CGRectContainsPoint