Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While making my program on Redhat based linux (amd64), I get this error:

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

Searching internet reveals that I have t install zlib 32bit version. A quick search shows that I have that package

[root@localhost trunk]# find / -name libz*

As you can see both /lib and /lib64 contain the libz file. Next I tried to find the ldd search path and it shows that both 32 bit and 64 bit folders are included

[root@localhost trunk]# ldconfig -v | grep -v ^$'\t'
/lib/i686: (hwcap: 0x0008000000000000)
/lib64/tls: (hwcap: 0x8000000000000000)  
/usr/lib64/tls: (hwcap: 0x8000000000000000)
/usr/lib64/sse2: (hwcap: 0x0000000004000000)
/lib/i686/nosegneg: (hwcap: 0x0028000000000000)

SO I wonder why still I get that error!!!!


I installed zlib-devel (both i686 and x86_64) and here is the confirmation

 [root@localhost trunk]# yum list zlib-devel
 Installed Packages
 zlib-devel.i686     1.2.3-27.el6             @sl
 zlib-devel.x86_64   1.2.3-27.el6             @sl

However still I get the same error.


After fixing the incorrect symbolic link, I now have

[root@localhost trunk]# ls -l /lib/*
lrwxrwxrwx. 1 root root    18 Feb 23 22:58 /lib/ -> /usr/lib64/
lrwxrwxrwx. 1 root root    13 Feb 18 12:06 /lib/ ->
-rwxr-xr-x. 1 root root 75332 Dec 10  2011 /lib/

But error still exists



I found that I have to install static libraries. Don't know why Makefile searches for static libraries! Please refer to my comments for the name of packages.

Thanks fuero for help

share|improve this question
If an answer helped you resolve your issue, you should indicate so by upvoting and accepting it. This also indicates to the system, and community, that the matter has been resolved. – Michael Kjörling Nov 15 '13 at 23:20
up vote 4 down vote accepted

Install zlib-devel or add a symlink to the lib directories.

yum list lists ALL packages, not just the installed ones. To find out whether it's installed, try this:

yum list installed | grep zlib

This is from a RHEL 6.3 reference system:

# rpm -ql zlib-devel
/usr/lib64/                  <---- the symlink I mentioned
# rpm -ql zlib-devel.i686
/usr/lib/                    <---- the symlink I mentioned

What the symlinks point to:

# ls /usr/lib/ -lhA
lrwxrwxrwx. 1 root root 23 Feb 23 20:32 /usr/lib/ -> ../../lib/
# ls /usr/lib64/ -lhA
lrwxrwxrwx. 1 root root 25 Feb 23 20:24 /usr/lib64/ -> ../../lib64/
share|improve this answer
see the updated answer – fuero Feb 23 '13 at 19:27
I think a wrong path is confusing ld. How can I find that? – mahmood Feb 23 '13 at 19:34
another update. don't forget to run ldconfig. Perhaps sharing how you call the compiler helps. – fuero Feb 23 '13 at 19:35
OK. The problem with -lz will be solved by installing static version of zlib named zlib-static. Now I am getting some other -l errors like -lm and that will be solved by installing glibc-static. I don't know why the program searches for static librsries – mahmood Feb 23 '13 at 20:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.