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/libz.so*
lrwxrwxrwx. 1 root root    18 Feb 23 22:58 /lib/libz.so -> /usr/lib64/libz.so
lrwxrwxrwx. 1 root root    13 Feb 18 12:06 /lib/libz.so.1 -> libz.so.1.2.3
-rwxr-xr-x. 1 root root 75332 Dec 10  2011 /lib/libz.so.1.2.3

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

  • 1
    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. – user Nov 15 '13 at 23:20

Install zlib-devel or add a libz.so 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/libz.so                  <---- the symlink I mentioned
# rpm -ql zlib-devel.i686
/usr/lib/libz.so                    <---- the symlink I mentioned

What the symlinks point to:

# ls /usr/lib/libz.so -lhA
lrwxrwxrwx. 1 root root 23 Feb 23 20:32 /usr/lib/libz.so -> ../../lib/libz.so.1.2.3
# ls /usr/lib64/libz.so -lhA
lrwxrwxrwx. 1 root root 25 Feb 23 20:24 /usr/lib64/libz.so -> ../../lib64/libz.so.1.2.3
  • 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

If it helps anyone - my issue was that cmake was running /usr/bin/g++ -static-libstdc++ which caused the error output: /usr/bin/ld: cannot find -lstdc++.

The fix (on RHEL/CentOS) was to run sudo yum install libstdc++-static.x86_64 since it was looking for the static lib.

  • It did help me, thank you :-) – hoefling Apr 1 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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