0
votes

gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/vagrant/python/include/python2.7 -c external/KentLib/wWigIO/wWigIO.c -o build/temp.linux-i686-2.7/external/KentLib/wWigIO/wWigIO.o -w -shared -fPIC -p -Iexternal/KentLib/inc

Then:

gcc -pthread -shared build/temp.linux-i686-2.7/external/KentLib/wWigIO/wWigIO.o -o build/lib.linux-i686-2.7/wWigIO.so -DMACHTYPE_x86_64 -lz -lm external/KentLib/lib/jkweb.a

(sorry for the messy-ness of these commands I wanted to copy them verbatim to avoid leaving out important details)

Then, I look at the symbols, and notice that compress is not defined:

$ nm build/lib.linux-i686-2.7/wWigIO.so | grep compress
         U compress
0002486d t getDecompressor
00024b28 T lineFileDecompress
00024c0f T lineFileDecompressFd
00024c8b T lineFileDecompressMem
         U uncompress
00037cd2 T zUncompress

It doesn't seem to be linking to the either libm or libz:

$ ldd build/lib.linux-i686-2.7/wWigIO.so
    linux-gate.so.1 =>  (0xb76e2000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb7668000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb74be000)
    /lib/ld-linux.so.2 (0xb76e3000)

I know that libz is installed and it's in the search path:

$ sudo cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
$ sudo cat /etc/ld.so.conf.d/*.conf
# Multiarch support
/lib/i386-linux-gnu
/usr/lib/i386-linux-gnu
/lib/i686-linux-gnu
/usr/lib/i686-linux-gnu
# libc default configuration
/usr/local/lib

libz is in those locations:

$ locate libz
/lib/i386-linux-gnu/libz.so.1
/lib/i386-linux-gnu/libz.so.1.2.3.4
/usr/lib/i386-linux-gnu/libz.a
/usr/lib/i386-linux-gnu/libz.so

I can see the symbol defined in libz.so

$ nm -D /usr/lib/i386-linux-gnu/libz.so | grep compress
00001d60 T compress
00001c70 T compress2
00001da0 T compressBound
00003d20 T uncompress

The only way I can get this to work is to change the gcc command to this (bold part is added):

gcc -pthread -shared build/temp.linux-i686-2.7/external/KentLib/wWigIO/wWigIO.o -o build/lib.linux-i686-2.7/wWigIO.so -DMACHTYPE_x86_64 -lz -lm external/KentLib/lib/jkweb.a /usr/lib/i386-linux-gnu/libz.a

This makes no sense to me. Why wouldn't libz be linking?

1
@JoachimPileborg, it does reference it... one of the source files calls compress(). That source file does #include <zlib.h>Scott Frazer

1 Answers

0
votes

I sort of figured out a solution.

If I set LDFLAGS='-Wl,--no-as-needed -lz' then it does indeed link to libz and the compiled shared library now does not get the undefined symbol error.

However, I'm still confused as to why it doesn't link to libz by just providing the -lz flag.