[cairo] Problem while compile cairo dll with fontconfig on MinGW

mpsuzuki at hiroshima-u.ac.jp mpsuzuki at hiroshima-u.ac.jp
Thu Feb 25 07:12:33 PST 2010

dvphuong.fet at gmail.com wrote:
> This is my building process.:
> This is the log of my building process:
> -----------------------------------------
> $ ./configure --enable-shared --disable-static CPPFLAGS=-I/usr/local/include
> LDFLAGS=-L/usr/local/lib PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
> lt_cv_deplibs_check_method=pass_all

> checking for FONTCONFIG... yes
> checking for FcFini... no

Hmm, it's first remarkable point for me. If fontconfig is
not so old (FcFini was introduced in 2003-Aug), I guess
the linker flags returned by pkg-config for fontconfig
does not include libexpat, libiconv, libfreetype and libz.
Something like...

  $ env PKG_CONFIG_PATH=... pkg-config --libs fontconfig -L... -lfontconfig

Anyway, current cairo configure checks the availability
of fontconfig by pkg-config. If the linking test is failed,
cairo configure does not think fontconfig is unusable but
recognize it as legacy version. The linker flag returned
by pkg-config is copied to FONTCONFIG_LIBS in Makefile
without modification.
Something like...

  FONTCONFIG_CFLAGS = -I.../include
  FONTCONFIG_LIBS = -L.../lib -lfontconfig

As you can find, in this phase, there is no dependency info
for libfontconfig (libexpat, libiconv, libfreetype, libz)
is reflected to the files generated by configure.
libfontconfig.la is our last hope to obtain the dependency
info. You can find libfontconfig.la includes full dependency
info aslike:

  # Libraries that this one depends upon.
  dependency_libs=' .../libfreetype.la ../libz.la -L... .../libexpat.la'

> /bin/sh ../libtool --tag=CC --mode=link gcc -g -O2 -version-info
> 10802:10:10800 -no-undefined -export-symbols cairo.def -L/usr/local/lib -o
> libcairo.la -rpath /usr/local/lib
> cairo-analysis-surface.lo cairo-arc.lo cairo-array.lo cairo-atomic.lo

  [snip the list of GNU libtool object files]

> cairo-ft-font.lo cairo-ps-surface.lo cairo-pdf-surface.lo
> cairo-deflate-stream.lo cairo-svg-surface.lo -LC:/msys/1.0/local/lib
> -lpixman-1 -LC:/msys/1.0/local/lib -lfreetype -LC:/msys/1.0/local/lib
> -lfontconfig -LC:/msys/1.0/local/lib -lpng12 -lgdi32 -lmsimg32 -lm
> -lz -lz -lm -lm

As FONTCONFIG_LIBS does not include libexpat, libiconv,
libfreetype and libz, the argument to GNU libtool in
linking mode does not include them. We expect GNU libtool
checks the content of libfontconfig.la and add required

> libtool: link: if test "x`/bin/sed 1q cairo.def`" = xEXPORTS; then cp
> cairo.def .libs/libcairo-2.dll.def; else echo EXPORTS >
> .libs/libcairo-2.dll.def; cat cairo.def >> .libs/libcairo-2.dll.def; fi
> libtool: link: gcc -shared .libs/libcairo-2.dll.def
> .libs/cairo-analysis-surface.o .libs/cairo-arc.o .libs/cairo-array.o

   [snip the list of GNU libtool object files]

> .libs/cairo-deflate-stream.o .libs/cairo-svg-surface.o -L/usr/local/lib
> -LC:/msys/1.0/local/lib /usr/local/lib/libpixman-1.a
> /usr/local/lib/libfreetype.a /usr/local/lib/libfontconfig.a
> /usr/local/lib/libpng12.a -lgdi32 -lmsimg32 -lz -o .libs/libcairo-2.dll
> -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker
> .libs/libcairo.dll.a

Oh, as you can see, GNU libtool does not add the libraries required
by libfontconfig. So you got following errors.

> C:/msys/1.0/local/lib/libfontconfig.a(fcfreetype.o): In function `FcFreeTypeQueryFace':
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:727: undefined reference to `libiconv_open'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:746: undefined reference to `libiconv'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:751: undefined reference to `libiconv_close'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:1663: undefined reference to `FT_Get_BDF_Property'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:1684: undefined reference to `FT_Get_BDF_Property'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:1544: undefined reference to `FT_Get_BDF_Property'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:1551: undefined reference to `FT_Get_BDF_Property'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:1573: undefined reference to `FT_Get_BDF_Property'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:756: undefined reference to `libiconv_close'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:737: undefined reference to `libiconv_close'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:1723: undefined reference to `FT_Get_X11_Font_Format'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcfreetype.c:1061: undefined reference to `FT_Get_BDF_Property'
> C:/msys/1.0/local/lib/libfontconfig.a(fcxml.o): In function `FcConfigMessage':
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcxml.c:466: undefined reference to `xmlSAX2GetLineNumber'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcxml.c:469: undefined reference to `xmlSAX2GetLineNumber'
> C:/msys/1.0/local/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcxml.c:2500: undefined reference to `xmlCreatePushParserCtxt'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcxml.c:2539: undefined reference to `xmlParseChunk'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcxml.c:2553: undefined reference to `xmlFreeParserCtxt'
> C:/msys/1.0/home/VIETPHUONG/fontconfig-2.8.0/src/fcxml.c:2544: undefined reference to `xmlCtxtGetLastError'
> collect2: ld returned 1 exit status
> make[3]: *** [libcairo.la] Error 1
> make[2]: *** [all] Error 2
> make[1]: *** [all-recursive] Error 1
> make: *** [all] Error 2

If you add the required libraries manually (by setting LIBS),
you can solve this problem.

> Now I try with the following configure command (add LIBS="-lexpat -liconv
> -lfreetype") and use libexpat instead of libxml2:

> It's ok, but I still don't understand what is reason?

I guess the dependency libraries are not added when GNU
libtool in your working source is linking shared library.

You may have another question; "there is -lfreetype, why
some FreeType symbols are unresolved?". It is related with
the order of archive library in the command line options.
If "libfreetype.a libfontconfig.a", the problem doesn't
occur. In fact, newer cairo (on GIT) is more careful about
the order of the libraries and does not cause this problem.


In summary, to avoid extra LIBS=... effort, what should
be done? The important question is:

Linking target should resolve all symbols in the objects?

# example of answers might be:
#   shared library: Win32=yes, Linux=no
#   binary executable: Win32=yes, Linux=yes

If the answer is yes, the carry-over of dependency libraries
is essential. The most reliable knowledge database about such
info would be GNU libtool. At least, GNU libtool 2.2.6b
(included in cairo-1.8.10 tarball) scans the dependency
from libfontconfig.la when -lfontconfig is given by the command
line option. So I think cairo-1.8.10 will proceed to better
status, although I cannot guarantee the success. Please try.

Today I have only Unix machines with cross MinGW compilers,
so I cannot reproduce the trouble you had - GNU libtool in
cross compiler environment prevents the linking of DLL from
objects and archive library (it's not standard way!).


More information about the cairo mailing list