内联函数"未定义符号"错误 [英] Inline function "undefined symbols" error

查看:248
本文介绍了内联函数"未定义符号"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个内联函数,但我得到一个错误。我怎样才能解决这个问题?

错误信息:

为i386硬件架构未定义的符号:
  _XYInRect,从引用:
       - [BeginAnimation ccTouchesEnded:withEvent:方法]在BeginAnimation.o
LD:符号(S)未找到i386硬件架构
铿锵:错误:连接命令,退出code 1(使用-v看看调用)失败

code:

  CGPoint位置= CGPointMake(60,350);如果(XYInRect(位置,53,338,263,369)){}内联BOOL XYInRect(CGPoint位置,浮MIXX,浮MixY,浮MAXX,浮MAXY){
    如果(location.x>&MIXX功放;&安培; location.y> MixY和放大器;&安培; location.x<&MAXX功放;&安培; location.y< MAXY){
        返回YES;
    }其他{
        返回NO;    }
}


解决方案

到C99 并没有< A HREF =htt​​p://gcc.gnu.org/onlinedocs/gcc/Inline.html#Inline> GNU语义学,这意味着原在线不同于这两种静态内联 extern内联

在特定的,原始的在线意味着该功能还有外部链接,但确定指标内联不提供外部的(你需要外部内联为)。

这意味着你需要在不同的翻译单元或连接额外的的extern 确定指标将失败。不过,你可能找静态内联

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;

    }
}

解决方案

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 defintion does not provide the external one (you'd need extern inline for that).

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

这篇关于内联函数&QUOT;未定义符号&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆