【问题标题】:undefined reference to ruserok error未定义对 ruserok 错误的引用
【发布时间】:2013-04-08 22:16:46
【问题描述】:

我遇到了一个奇怪的“未定义引用”编译错误,我似乎找不到解决方法。我正在尝试使用 Yocto Project 生成的 ARM 编译器 (arm-poky-linux-gnueabi-gcc) 为我的 Gumstix Overo 配置/编译 PAM 1.1.6,但在编译过程中我不断收到以下错误:

.libs/pam_rhosts.o: In function `pam_sm_authenticate':
modules/pam_rhosts/pam_rhosts.c:117: undefined reference to `ruserok'
collect2: error: ld returned 1 exit status

所以,我做了一些调查,发现在配置过程中,编译并执行了以下测试代码,以确定 ruserok、ruserok_af 和 iruserok 的可用性。

/* end confdefs.h.  */
/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
#define $2 innocuous_$2

/* System header to define __stub macros and hopefully few prototypes,
    which can conflict with char $2 (); below.
    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
    <limits.h> exists even on freestanding compilers.  */

#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif

#undef $2

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char $2 ();
/* The GNU C library defines this for functions which it implements
    to always fail with ENOSYS.  Some functions are actually named
    something starting with __ and the normal name is an alias.  */
#if defined __stub_$2 || defined __stub___$2
choke me
#endif

int
main ()
{
return $2 ();
  ;
  return 0;
}

所以,我复制、粘贴(将所有 $2 替换为 ruserok)并使用生成的 GCC 编译器编译了这段代码

./arm-poky-linux-gnueabi-gcc -o test.o test.c

查看 ruserok、ruserok_af 和 iuserok 函数是否存在,我收到以下编译错误:

/tmp/ccU8YszI.o: In function `main':
test.c:(.text+0x8): undefined reference to `ruserok'
collect2: error: ld returned 1 exit status

这与上面的“未定义对 `ruserok' 的引用”错误相同。作为一个完整性检查,由于我之前通过 Ubuntu 软件中心安装了 Ubuntu/Linaro ARM GCC 编译器,所以我使用 arm-linux-gnueabi-gcc 编译器编译了相同的代码,但编译的代码没有任何错误。这里是我用来参考的命令:

arm-linux-gnueabi-gcc -o test.o test.c

所以,我的问题是:为什么一个编译器会产生“未定义的 ruserok 引用”错误,而另一个不会?或者换种方式问,两个编译器有什么区别,一个编译器会产生“未定义的ruserok引用”错误?

【问题讨论】:

    标签: compiler-construction compiler-errors arm undefined-reference


    【解决方案1】:

    编译器(尤其是gcc)不仅仅是代码生成器。他们非常熟悉 libc 或标准 C 库以及 libgcc 编译器帮助库。通用命令行隐式使用 -lc(与 libc 链接)。来自 Ubuntu 的 arm-linux-gnueabi-gcc 是一个带有 eglibc 的 crosstool-ng 版本。

    我不知道Poky gcc 是关于什么的。您可能会提供指向您从何处获得编译器的链接。从Poky configuration link 看来,编译器似乎是一个多库发行版或其他东西,您可能需要执行其他步骤来配置cross-build

    问题的答案,

    为什么一个编译器会产生“未定义的 ruserok 引用”错误,而另一个不会?

    因为一个库中有ruserok 而另一个没有(或未配置为查看它)。

    【讨论】:

    • 感谢您的回答。它为我的编译过程提供了一些启示。但是要回答您关于 Poky 编译器的问题,它是使用 Bitbake (bitbake.berlios.de) 工具从头构建的,该工具与 Yocto 项目 (www.yoctoproject.com) 的一部分的 Poky 发行版一起打包。那么,ruserok 是否存在于 libc 库中?
    • 好吧,我刚刚找到了我的 libc 问题的答案,是的,ruserok、ruserok_ad 和 iuserok 确实存在于 libc 中。
    猜你喜欢
    • 2016-10-03
    • 2021-09-07
    • 2012-02-27
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多