Forum OpenACS Q&A: gcc -lz option

Collapse
Posted by Jose Leviaguirre on
I get the following error when compiling nsxml.so:

cannot find -lz

does anybody knows what this is for?

This error is generated when doing:

root# gcc -shared -nostartfiles -o nsxml.so ns_xml.o -L/usr/lib -lxml2 -lz -lm
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: ** [nsxml.so] Error 1

however, if I remove the -lz option it compile perfectly. I am afraid it this will affect. I'm sure it will but.. how bad?. I want to do it the proper way. Please help.

Collapse
2: Re: gcc -lz option (response to 1)
Posted by Patrick Giagnocavo on
The -l flag means "link against these libraries when compiling the code" .

Thus, just as -lxml2 refers to "libxml2" and -lm refers to "libm" (math library), it is reasonable to assume that -lz refers to libz, which I would guess is a compression library.

If you run "locate libz" or failing that, "find / -name libz -print" , do you get any filenames?  Perhaps the library is just in a different location.

Collapse
3: Re: gcc -lz option (response to 1)
Posted by Jose Leviaguirre on
Thanks Patrick!

'make' was looking for libz.so so I create a symbolic link to libz.so.1

Here:
[root@jleviagu nsxml]# locate libz
/usr/lib/libz.so.1
/usr/lib/libz.so.1.1.3
/usr/lib/libzvt.so.2.2.10
/usr/lib/libzvt.so.2
/usr/lib/gaim/libzephyr.la
/usr/lib/gaim/libzephyr.so
[root@jleviagu nsxml]# ln -s /usr/lib/libz.so.1 /usr/lib/libz.so

Then I compiled the nsxml source
[root@jleviagu lib]# cd /usr/local/src/aolserver/nsxml/
[root@jleviagu nsxml]# make
/bin/rm -f nsxml.so
gcc -shared -nostartfiles -o nsxml.so ns_xml.o -L/usr/lib -lxml2 -lz -lm

and move the compiled nsxml.so into /usr/local/aolserver/bin

[root@jleviagu[root@jleviagu nsxml]# mv nsxml.so /usr/local/aolserver/bin/

I wonder if I should make the link to libz.so.1.1.3