Fedora 35 has library libz compiled without the -fPIC option

I am trying to compile an application which links to the system’s libz library but the compilation process requires the use of the -fPIC option to create a position independent code. So, when the linker attempts to link all the components together it reports the following error:

/usr/bin/ld: /usr/lib64/libz.a(deflate.o): warning: relocation against `z_errmsg' in read-only section `.text'
/usr/bin/ld: /usr/lib64/libz.a(zutil.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value

which indicates that system’s libz library is compiled without this option and therefore it cannot be used. So here are my questions:

  1. Why is it that the system’s libz is not compiled with the -fPIC option?

  2. Can I produce another modified rpm package for libz, based on the original one, which contains an updated version of this library compiled with the -fPIC option? Is this going to create problems with other system components?

Thanks in advance

1 Like

zlib on Fedora provides both the shared object and the static library.

You seem to have the static package installed, which is why you’re getting the static library. Can you please post the output of

rpm -q zlib\*

?

We need to use zlib-devel. You probably have zlib-static installed. Here’s what’s on my system:

$ ls /usr/lib64/libz.*
/usr/lib64/libz.so  /usr/lib64/libz.so.1  /usr/lib64/libz.so.1.2.11

$ rpm -qa \*zlib\*
zlib-1.2.11-31.fc36.x86_64
zlib-devel-1.2.11-31.fc36.x86_64
zlib-1.2.11-31.fc36.i686
zlib-devel-1.2.11-31.fc36.i686