hidden symbol `stat' in libc_nonshared.a(stat.

2019-09-18 18:04发布

问题:

I'm trying to use methods contained in a shared library (libscplugin.so).

I have satisfied all of the libraries requirements:

  • libc.so with a symlink to libc.so.6
  • libz.so with a symlink to libz.so.1.2.8
  • libstdc++.so with a symlink to libstdc++.so.6.0.20

Upon compilation I get the following error message:

$ gcc test.c -o test -L/usr/lib/arm-linux-gnueabihf/ -lscplugin
/usr/bin/ld: test: hidden symbol `stat' in /usr/lib/arm-linux-gnueabihf/libc_nonshared.a(stat.oS) is referenced by DSO
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

The only reference I could find to libc_nonshared.a is in /usr/lib/arm-linux-gnueabihf/libc.so:

$ cat libc.so
/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /lib/arm-linux-gnueabihf/libc.so.6 /usr/lib/arm-linux-gnueabihf/libc_nonshared.a  AS_NEEDED ( /lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 ) )

In test.c I'm attempting to use two functions of the shared library (totally unrelated to stat). What can I do to get this to compile ?

回答1:

Your problem is here:

I have satisfied all of the libraries requirements:

  • libc.so with a symlink to libc.so.6

That is not a valid setup for glibc. libc.so is supposed to be a text file (linker script) as you saw at the end of your answer. You're doing something weird and unnecessary if you're making symlinks to shared libraries like this yourself. Use the libc.so that's provided (and you need to do this when building your other shared libraries -- your problem right now is that they were mis-linked) and everything will work fine.