Samik
Samik

Reputation: 575

lgcc_s not found by ld even if libgcc_s.so link is not broken on Ubuntu 12.10

I'm facing a problem compiling with gcc with -static, -static-libgcc flags enabled for compiler and -Wl,-static flag enabled for linker on Ubuntu 12.10. But the application builds fine with dynamic linking (without using those flags).

/usr/bin/ld: cannot find -lgcc_s

After looking at the suggestions over the internet, I found most of the time it's a problem with broken link from /usr/lib/gcc/i686-linux-gnu/x.x/libgcc_s.so to /lib/libgcc_s.so.1. But in my case /usr/lib/gcc/i686-linux-gnu/4.7/libgcc_s.so is pointing to /lib/i386-linux-gnu/libgcc_s.so.1 which does exist.

$ ls -l /usr/lib/gcc/i686-linux-gnu/4.7/libgcc_s.so
lrwxrwxrwx 1 root root 33 Sep 21  2012 /usr/lib/gcc/i686-linux-gnu/4.7/libgcc_s.so -> /lib/i386-linux-gnu/libgcc_s.so.1
$ ls -l /lib/i386-linux-gnu/libgcc_s.so.1
-rw-r--r-- 1 root root 116244 Sep 21  2012 /lib/i386-linux-gnu/libgcc_s.so.1
$ file /lib/i386-linux-gnu/libgcc_s.so.1
/lib/i386-linux-gnu/libgcc_s.so.1: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x61fa08eda0f264222649f9481f9e0340567d0862, stripped

The output of ldconfig shows the following:

$ sudo /sbin/ldconfig -v | grep libgcc_s
/sbin/ldconfig.real: Can't stat /lib/i686-linux-gnu: No such file or directory
/sbin/ldconfig.real: Can't stat /usr/lib/i686-linux-gnu: No such file or directory
/sbin/ldconfig.real: Path `/lib/i386-linux-gnu' given more than once
/sbin/ldconfig.real: Path `/usr/lib/i386-linux-gnu' given more than once
    libgcc_s.so.1 -> libgcc_s.so.1
/sbin/ldconfig.real: Cannot stat /usr/lib/i386-linux-gnu/libsoftokn3.so: No such file or directory
/sbin/ldconfig.real: Cannot stat /usr/lib/i386-linux-gnu/libnss_db.so: No such file or directory

Can anyone help me solve this problem with static linking? Also let me know if any further details is needed. Thanks.

Upvotes: 2

Views: 11934

Answers (1)

Marcelo MD
Marcelo MD

Reputation: 1769

Probably your linker can't find libgcc_s.a, the static version of libgcc_s.so.

Try passing -Wl,--verbose=99 to the linker and see what comes up.

I had a similar problem a while ago. Using the linker options gave the answer:

...
attempt to open /long_path/usr/lib/libgcc_s.so failed
attempt to open /long_path/usr/lib/libgcc_s.a failed
attempt to open /long_path/lib/libgcc_s.a failed
attempt to open /long_path/lib/libgcc_s.so succeeded
...

As far as I know, .so stands for "shared object". I guess .a for archive (a collection of compiled objects).

Upvotes: 5

Related Questions