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

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
=============================================================================================================================================================================================================================================
Installing:
 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 

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

Complete!

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: SXI ADMIN

The author is the creator of SXI LLC 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.