fa.openbsd.tech
[Top] [All Lists]

libfreetype linkage with libz. Correct behavior?

Subject: libfreetype linkage with libz. Correct behavior?
From: Edd Barrett <vext01@xxxxxxxxx>
Date: Wed, 30 Jul 2008 20:05:14 UTC
Newsgroups: fa.openbsd.tech

Hi,

You may have seen me post on misc@ regarding a library linkage problem:
http://www.nabble.com/Odd-linking-message-(please-relink-your-binary)-td18695435.html

Jonathan Kew has been working with me on this and we are wondering why
libfreetype does not reference libz. This was the reason the XeTeX build
was not behaving as expected for us. The machine in question here is
OpenBSD-4.3-stable i386.

Jonathan provides below a test case. Is this the behavior you guys would
expect? If so why?

Thanks

----- Forwarded message from Jonathan Kew <jonathan_kew@xxxxxxx> -----

Delivered-To: vext01@xxxxxxxxx
Authentication-Results: mx.google.com; spf=pass (google.com: domain of
        jonathan_kew@xxxxxxx designates 208.145.81.51 as permitted sender)
        smtp.mail=jonathan_kew@xxxxxxx
X-CGP-ClamAV-Result: CLEAN
X-VirusScanner: Niversoft's CGPClamav Helper v1.78 (ClamAV engine v0.93.3)
Cc: Karl Berry <karl@xxxxxxxxxxxxxxx>
From: Jonathan Kew <jonathan_kew@xxxxxxx>
To: Edd <vext01@xxxxxxxxx>
In-Reply-To: <20080730091430.GF2124@xxxxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: link problem again -- explanation & workaround
Date: Wed, 30 Jul 2008 16:04:44 +0100
X-Mailer: Apple Mail (2.926)
X-Scanned-By: MIMEDefang 2.62 on 172.22.0.51

On 30 Jul 2008, at 10:14 AM, Edd wrote:

> On Wed, Jul 30, 2008 at 10:12:38AM +0100, Jonathan Kew wrote:
>> I'll see if I can figure out how to build *without* using TL's  
>> freetype2
>> at all; if it's a standard part of the base OpenBSD installation,  
>> that
>> should be OK.

OK, I think I understand. The details:

Just using  --with-system-freetype2  by itself fails because it doesn't 
find the freetype library or headers in /usr/X11R6.

Adding  --with-freetype2-libdir=/usr/X11R6/lib --with-freetype2- 
include=/usr/X11R6/include  OUGHT to work, because that tells it where to 
look for the library and headers.

However, this fails because of what I think is a flaw in the OpenBSD  
freetype lib that's installed: it is linked (dynamically) against zlib, but 
it doesn't have the proper information for the linker to pull this in. (Is 
that something to do with RPATH, or what? I don't know much about all this 
stuff.) The result is that the configure test (executed by the top-level 
configure, and by libs/configure) concludes that system-freetype2 is 
missing or broken, and so it falls back on TL's private copy (you'll see a 
warning message in the configure output, captured in build.log).

To demonstrate this, I tried the following test program:

    #include "ft2build.h"
    #include FT_FREETYPE_H

    int main()
    {
        FT_Library lib;
        FT_Error   err;
        err = FT_Init_FreeType(&lib);
        if (err == 0)
            FT_Done_FreeType(lib);
        return 0;
    }

Try compiling this, passing it the appropriate -I and -L flags, and - 
lfreetype:

obsd43-i386% gcc -I/usr/X11R6/include -I/usr/X11R6/include/freetype2 
-L/usr/X11R6/lib -o test test.c -lfreetype

IMO, this should work (and it does on other platforms), but on OpenBSD it 
fails to link:

/usr/X11R6/lib/libfreetype.so.16.0: undefined reference to `inflate'
/usr/X11R6/lib/libfreetype.so.16.0: undefined reference to `inflateReset'
/usr/X11R6/lib/libfreetype.so.16.0: undefined reference to `inflateEnd'
/usr/X11R6/lib/libfreetype.so.16.0: undefined reference to `inflateInit2_'
    collect2: ld returned 1 exit status

Sure enough, if we inspect libfreetype.so.16.0, it doesn't refer to libz:

    obsd43-i386% ldd /usr/X11R6/lib/libfreetype.so.16.0
    /usr/X11R6/lib/libfreetype.so.16.0:
            Start    End      Type Open Ref GrpRef Name
0dcab000 2dcc3000 dlib 1    0   0      /usr/X11R6/lib/libfreetype.so.16.0

Compare this with libfontconfig, which *does* know about the libraries it 
depends on:

    obsd43-i386% ldd /usr/X11R6/lib/libfontconfig.so.5.1
    /usr/X11R6/lib/libfontconfig.so.5.1:
            Start    End      Type Open Ref GrpRef Name
0ac6c000 2ac7d000 dlib 1    0   0      /usr/X11R6/lib/libfontconfig.so.5.1
0f980000 2f989000 rlib 0    1   0      /usr/lib/libexpat.so.9.0
            0df3f000 2df47000 rlib 0    1   0      /usr/lib/libz.so.4.1
033e1000 233f9000 rlib 0    1   0      /usr/X11R6/lib/libfreetype.so.16.0

*** Why doesn't libfreetype have a similar reference to libz? That seems 
wrong to me; I think it was not built correctly. Edd, can you follow up on 
this and report it appropriately, assuming it really is a bug? ***

To work around the problem, I first tried some really hacky stuff with CC, 
CXX, etc., but actually you can just use  LDFLAGS  to force -lz into the 
link in all cases (including the configure-time tests for freetype; just 
using TL's  --with-system-zlib  doesn't achieve that):

    LDFLAGS=-lz TL_MAKE=gmake ./Build \
        --with-system-freetype2 \
        --with-freetype2-libdir=/usr/X11R6/lib \
        --with-freetype2-include=/usr/X11R6/include \
        --with-fontconfig=/usr/X11R6

This seems to work, giving me a xetex binary that uses only the system  
freetype2, and not building texlive's libs/freetype2 at all. This should be 
OK to ship because if fontconfig is present, freetype2 must also be present 
on the system.

JK


----- End forwarded message -----

-- 

Best Regards
Edd

http://students.dec.bmth.ac.uk/ebarrett


<Prev in Thread] Current Thread [Next in Thread>