CentOS 5.2 + Qt 4.5 + FcFreeTypeQueryFace

So with all the buzz around the new release of Qt 4.5, you may be like me and have been desperately wanting to give it a whirl. Has this happened to you yet?

/opt/qtsdk-2009.01/qt/lib/ undefined reference to `FcFreeTypeQueryFace'
collect2: ld returned 1 exit status

Someone’s got some ‘splainin to do. Lucky for you, that’s me. Basically, the people at fontconfig did not add this API call until 2.4.2. From fontconfig’s ChangeLog 2.4.2:

commit 72ffe6536a6825a32095c8185aff836a12326ac5
Author: Keith Packard 
Date:   Sat Dec 2 13:22:27 2006 -0800

    Add FcFreeTypeQueryFace external API. Bug #7311.
    Expose ability to build an FcPattern directly from an FT_Face
    object.            |    4 ++--
 doc/fcfreetype.fncs     |   17 +++++++++++++++-
 fontconfig/fcfreetype.h |    6 ++++++
 src/fcfreetype.c        |   50 ++++++++++++++++++++++++++---------------------
 4 files changed, 52 insertions(+), 25 deletions(-)

Problem is for us CentOS 5.2 users, we’re given a version 2.4.1-7 from “upstream” 😦 It’s not a big deal, we can just compile fontconfig from source … wait, did I just say compile? No worries, it’s easy.

1. Compile fontconfig 2.4.2 from source

Note: Throughout this step, I used fontconfig 2.4.2 since this is the minimum required version, but I tested this with the latest version 2.6.0 so just replace the version numbers accordingly if you choose to use 2.6.0.

[user@localhost ~]$ cd /usr/src
[user@localhost /usr/src]$ wget
[user@localhost /usr/src]$ tar -zxf fontconfig-2.4.2.tar.gz
[user@localhost /usr/src]$ cd fontconfig-2.4.2
[user@localhost /usr/src/fontconfig-2.4.2]$ ./configure --prefix=/opt/fontconfig-2.4.2
... (note: 'configure' output omitted for brevity) ...
[user@localhost /usr/src/fontconfig-2.4.2]$ make
... (note: 'make' output omitted for brevity) ...
[user@localhost /usr/src/fontconfig-2.4.2]$ make install
... (note: 'make install' output omitted for brevity) ...

Note: I chose to install into /opt/fontconfig-2.4.2 since I like keeping my “deviations” from upstream organized.

2. Add the fontconfig library location to your project’s .pro file

LIBS += -L/opt/fontconfig-2.4.2/lib

3. Recompile and that’s it! 😎

Now I can’t guarantee you will not have any ‘make’ errors due to library dependencies but I’m pretty sure that if you got as far as you did to receive this error, you will have every *-devel package needed by fontconfig already installed on your system.