内联函数“未定义符号”错误 [英] Inline function "undefined symbols" error
问题描述
我想写一个内联函数,但我得到一个错误。如何解决?
I want to write an inline function, but I get an error. How can I fix it?
错误信息:
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 ,这意味着原始内联
与两者不同 static inline
和 extern inline
。
Clang defaults to C99 and not GNU sematics, which means a raw inline
is different from both static inline
and extern inline
.
原始 inline
表示该函数仍然具有外部链接,但是内联定义不提供外部链接(您需要 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).
这意味着你需要一个额外的 extern
不同的翻译单元或链接将失败。但是,您可能正在寻找 static inline
。
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
.
这篇关于内联函数“未定义符号”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!