undefined reference to ruserok error

懵懂的女人 提交于 2019-12-11 12:03:09

问题


I've run into a strange "undefined reference to" compile error that I cannot seem to find a resolution for. I'm trying to configure/compile PAM 1.1.6 for my Gumstix Overo using the Yocto Project generated ARM compiler (arm-poky-linux-gnueabi-gcc), but I keep getting the following error during compilation:

.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

So, I did a some investigating and found out that during configure, the following test code is compiled and executed to determine the availability of ruserok, ruserok_af and 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;
}

So, I copied, pasted (replacing all of the $2's with ruserok) and compiled this code using the generated GCC compiler

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

to see if the ruserok, ruserok_af and iuserok functions do/don't exist, and I received the following compilation error:

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

which, is the same "undefined reference to `ruserok'" error as above. As a sanity check, since I had installed the Ubuntu/Linaro ARM GCC compiler through the Ubuntu Software center earlier, I compiled the same code with the arm-linux-gnueabi-gcc compiler, but the code compiled fine without any errors. Here the command I used for reference:

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

So, my question is: Why would one compiler produce an "undefined reference to ruserok" error, while the other does not? Or asked differently, what is the difference between the two compilers that one compiler would produce an "undefined reference to ruserok" error?


回答1:


Compilers (and in particular gcc) are more than just code generators. They are intimately familiar with the libc, or standard C library and also the libgcc compiler helper library. General command lines implicitly use -lc (link with libc). The arm-linux-gnueabi-gcc from Ubuntu is a crosstool-ng build with an eglibc.

I have no idea what the Poky gcc is about. You might provide a link to where you got the compiler from. From the Poky configuration link, it seems that the compiler is a mult-lib distribution or something and there are probably additional steps that you need to perform to configure the cross-build.

The answer to the question,

Why would one compiler produce an "undefined reference to ruserok" error, while the other does not?

Because one has ruserok in the library and the other doesn't (or isn't configured to see it).



来源:https://stackoverflow.com/questions/15890007/undefined-reference-to-ruserok-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!