Inline function “undefined symbols” error

2019-01-14 15:45发布

I want to write an inline function, but I get an error. How can I fix it?

Error information:

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)

Code:

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条回答
可以哭但决不认输i
2楼-- · 2019-01-14 15:52

Also would suggest using CGRectContainsPoint

查看更多
Root(大扎)
3楼-- · 2019-01-14 16:04

I think XYInRect() needs to be known prior to being used. Move the function definition to some place in the file before you call it.

查看更多
劫难
4楼-- · 2019-01-14 16:10

Clang defaults to C99 and not GNU sematics, which means a raw inline is different from both static inline and extern inline.

In particular, a raw inline means that the function still has external linkage, but the inline definition does not provide the external one (you'd need extern inline for that).

What this means is that you need an additional extern definition in a different translation unit or linking will fail. However, you're probably looking for static inline.

查看更多
登录 后发表回答