Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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*
/lib64/libz.so.1
/lib64/libz.so.1.2.3
/lib/libz.so.1
/lib/libz.so.1.2.3
/usr/lib64/libz.so
/usr/lib64/purple-2/libzephyr.so
/usr/lib64/libzip.so.1.0.0
/usr/lib64/libzip.so.1

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'
/usr/lib64/ctapi:
/usr/lib64/mysql:
/usr/lib64/tcl8.5/tclx8.4:
/usr/lib64/xulrunner-2:
/lib:
/lib64:
/usr/lib:
/usr/lib64:
/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!!!!

UPDATE

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.

UPDATE 2

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

SOLUTION

SOLUTION

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
add comment

1 Answer

up vote 1 down vote accepted

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/include/zconf.h
/usr/include/zlib.h
/usr/lib64/libz.so                  <---- the symlink I mentioned
/usr/lib64/pkgconfig/zlib.pc
/usr/share/doc/zlib-devel-1.2.3
/usr/share/doc/zlib-devel-1.2.3/README
/usr/share/doc/zlib-devel-1.2.3/algorithm.txt
/usr/share/doc/zlib-devel-1.2.3/example.c
/usr/share/doc/zlib-devel-1.2.3/minigzip.c
/usr/share/man/man3/zlib.3.gz
# rpm -ql zlib-devel.i686
/usr/include/zconf.h
/usr/include/zlib.h
/usr/lib/libz.so                    <---- the symlink I mentioned
/usr/lib/pkgconfig/zlib.pc
/usr/share/doc/zlib-devel-1.2.3
/usr/share/doc/zlib-devel-1.2.3/README
/usr/share/doc/zlib-devel-1.2.3/algorithm.txt
/usr/share/doc/zlib-devel-1.2.3/example.c
/usr/share/doc/zlib-devel-1.2.3/minigzip.c
/usr/share/man/man3/zlib.3.gz

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
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
add comment

Your Answer

 
discard

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.