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

时间:2012-04-20 08:50:07

标签: objective-c c compiler-errors inline 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)

代码:

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;

    }
}

3 个答案:

答案 0 :(得分:36)

Clang defaults to C99而非GNU sematics,这意味着原始inlinestatic inlineextern inline不同。

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

还建议使用CGRectContainsPoint