内联函数“未定义符号"错误 [英] 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 语义,这意味着原始 inline
不同于 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屋!