21

I am attempting to compile a program with g77 and I keep getting the following error:

/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status

I saw on another forum that this is related to libgcc, when looking for libgcc I get

>find /usr/ -name libgcc*

/usr/share/doc/libgcc1
/usr/share/lintian/overrides/libgcc1
/usr/lib/libgccpp.so.1.0.3
/usr/lib/libgccpp.so.1
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc_s_32.so
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc_s.so
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/32/libgcc_s_32.so
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/32/libgcc_s.so
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/32/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/32/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc.a
/usr/lib/ure/lib/libgcc3_uno.so
2
  • I've tried exporting the path to /usr/lib/gcc/x86_64-linux-gnu/3.4.6, /usr/lib/gcc/x86_64-linux-gnu/4.6, and /usr/lib, but no luck. Any ideas?
    – Biz
    Sep 16, 2013 at 20:00
  • Try sudo apt-get install ia32-libs
    – Mitch
    Sep 17, 2013 at 5:42

2 Answers 2

6

This is because although libgcc is present, it may not be in the paths known to ldconfig. Check this by doing:

sudo /sbin/ldconfig -p | grep libgcc

Does the output show that the link to libgcc corresponds to paths that you have listed above?

A workaround for you may be to add the link to the relevant library to your compile command e.g.

g++ program.cpp -L /usr/lib/gcc/x86_64-linux-gnu/4.6/

Another solution may be to create a symbolic link to the library yourself.

 ln -s /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so /usr/lib/gcc/libgcc_s.so
3
  • In response to 'sudo /sbin/ldconfig -p | grep libgcc' I got ' libgccpp.so.1 (libc6,x86-64) => /usr/lib/libgccpp.so.1 libgcc_s.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libgcc_s.so.1'. Tried with those paths, but no luck. tried with symbolic link but no luck with that either.
    – Biz
    Sep 16, 2013 at 23:41
  • Also, I'm using g77 to compile
    – Biz
    Sep 17, 2013 at 2:58
  • 2
    sudo is not needed for ldconfig -p Nov 22, 2017 at 14:48
0

https://blog.andrewbeacock.com/2007/10/how-to-add-shared-libraries-to-linuxs.html

Create a new file in /etc/ld.so.conf.d/ called .conf

Edit the file and add a line per directory of shared libraries (*.so files), it will look something like:

/usr/lib/APPLICATION/lib

Reload the list of system-wide library paths:

sudo ldconfig

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .