Linux: /usr/bin/ld: cannot find -lc Error and Solution

last updated in Categories

I‘m trying to compile mini_sendmail as described here. But I’m getting the following error after tying the make command:

gcc -O -c mini_sendmail.c
gcc -O -s -static mini_sendmail.o -o mini_sendmail
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
make: *** [mini_sendmail] Error 1

How do I fix this problem under RHEL 6?

You need to install the glibc-static package. It contains the C library static libraries for -static linking. You don’t need these, unless you link statically, which is highly discouraged. But mini_sendmail is specially used for chrooted setup. To install this login as root and type the following command:
# yum install glibc-static
Sample outputs:

Loaded plugins: rhnplugin
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package glibc-static.x86_64 0:2.12-1.7.el6_0.5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

 Package                                              Arch                                           Version                                                     Repository                                                             Size
 glibc-static                                         x86_64                                         2.12-1.7.el6_0.5                                            rhel-x86_64-server-optional-6                                         1.4 M

Transaction Summary
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 1.4 M
Installed size: 0  
Is this ok [y/N]: y
Downloading Packages:
glibc-static-2.12-1.7.el6_0.5.x86_64.rpm                                                                                                                                                                              | 1.4 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : glibc-static-2.12-1.7.el6_0.5.x86_64                                                                                                                                                                                  1/1 

  glibc-static.x86_64 0:2.12-1.7.el6_0.5                                                                                                                                                                                                     


Now, you can compile mini_sendmail without any problem under RHEL 6. Please note that RHEL v5 and earlier included static lib in glibc-devel itself.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

9 comment

  1. I had this some days ago when compilin some lib, i needed to install “zlib1g-dev” – so it is not always this ;)

  2. Hi ,

    I am facing problem while installing some commercial softwares

    the error i get is

    /usr/bin/ld: cannot find -lXm

    Kindly help me


  3. I ran into this exact problem, and I went to follow your instructions. It seems that RHEL has dropped glibc-static from its repos though. Do you know anything about this? Is it in some other repo somewhere? Can I download it and install it manually from somewhere?

  4. I am installing a program, and I have following problems, errors:
    /usr/bin/ld: cannot find -lpdb
    /usr/bin/ld: cannot find -lpml
    /usr/bin/ld: cannot find -lscore
    /usr/bin/ld: cannot find -lXGF
    /usr/bin/ld: cannot find -lXGC
    Kindly help me


  5. Thanks for that, my RHEL-fu was weak … I was trying to build runit and had provided glibc-devel … hadn’t realised it was looking for the static version until I strace’d the failing ld command :-) And your post filled in the last piece after a couple of seconds googling …

  6. Many thanks :) Saved life.
    Faced this problem during installing runit.

    If someone faces just install glibc-static. :)

  7. i’m building an rpm package from source(pg_bulkload) and i get this error

    ldl -lm -o pg_bulkload
    /usr/bin/ld: cannot find -lpam
    collect2: ld returned 1 exit status
    make[1]: *** [pg_bulkload] Error 1
    make[1]: Leaving directory `/home/vagrant/rpmbuild/BUILD/pg_bulkload-3.1.7/bin’
    make: *** [all] Error 2
    error: Bad exit status from /var/tmp/rpm-tmp.3UxTlz (%install)

    any ideas if its a package i haven’t installed?

    Still, have a question? Get help on our forum!