1

我遇到了一个奇怪的“未定义引用”编译错误,我似乎找不到解决方案。我正在尝试使用 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 引用”错误?

4

1 回答 1

0

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

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

问题的答案,

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

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

于 2013-04-08T23:01:50.610 回答