Re: What to do with “Fix FTBFS with ld --as-needed” bugs ?
On 2010-12-06 09:14:15 +0900, Charles Plessy wrote:
> - I do not understand what problem the patch solves when reordering ‘-lm -lz
> -L.. -lbam’ to ’-L.. -lbam -lm -lz’. It seems that it is related to the use
> of --as-needed. Is there a general explanation somewhere, that I can use
> when forwarding the patch upstream ?
Here is a part of the build log from Lucas' Ubuntu archive rebuild:
,----[ http://people.ubuntuwire.org/~lucas/ubuntu-nbs/32/samtools_0.1.10-1_lubuntu32.buildlog ]-
| gcc -g -Wall -O2 -I.. calDepth.c -o calDepth -lm -lz -L.. -lbam
| ../libbam.a(bgzf.o): In function `deflate_block':
| /build/user-samtools_0.1.10-1-i386-phvH6d/samtools-0.1.10/bgzf.c:272: undefined reference to `deflate'
| /build/user-samtools_0.1.10-1-i386-phvH6d/samtools-0.1.10/bgzf.c:274: undefined reference to `deflateEnd'
| /build/user-samtools_0.1.10-1-i386-phvH6d/samtools-0.1.10/bgzf.c:266: undefined reference to `deflateInit2_'
| /build/user-samtools_0.1.10-1-i386-phvH6d/samtools-0.1.10/bgzf.c:290: undefined reference to `deflateEnd'
| /build/user-samtools_0.1.10-1-i386-phvH6d/samtools-0.1.10/bgzf.c:306: undefined reference to `crc32'
| /build/user-samtools_0.1.10-1-i386-phvH6d/samtools-0.1.10/bgzf.c:307: undefined reference to `crc32'
I'm no expert on this topic but as far as I understand it it's because
-lbam (libbam.a) uses symbols from -lz and order matters with
,----[ 3rd paragraph for '-l' in 'man ld' ]-
| The linker will search an archive only once, at the location where
| it is specified on the command line. If the archive defines a
| symbol which was undefined in some object which appeared before the
| archive on the command line, the linker will include the
| appropriate file(s) from the archive. However, an undefined symbol
| in an object appearing later on the command line will not cause the
| linker to search the archive again.
| This type of archive searching is standard for Unix linkers.
Changing the order makes -lz gets processed after -lbam (which needs symbols