[racket] How to compile C libraries that use Cairo?

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Nov 17 12:51:35 EST 2013

2013/11/17 Matthew Flatt <mflatt at cs.utah.edu>:

> I think the compatibility library version is determined by linking, not
> by header files, so my guess is that you didn't link against the Racket
> "libcairo.2.dylib".

You are spot on. Using otool -L reveals that librsvg was linked with
the macports
version of libcairo.

mba-5:librsvg-2.36.4 soegaard$ otool -L /usr/local/lib/librsvg-2.2.dylib
/usr/local/lib/librsvg-2.2.dylib:
/usr/local/lib/librsvg-2.2.dylib (compatibility version 39.0.0,
current version 39.4.0)
/opt/local/lib/libgdk_pixbuf-2.0.0.dylib (compatibility version
3001.0.0, current version 3001.1.0)
/opt/local/lib/libgio-2.0.0.dylib (compatibility version 3801.0.0,
current version 3801.2.0)
/opt/local/lib/libpangocairo-1.0.0.dylib (compatibility version
3601.0.0, current version 3601.1.0)
/opt/local/lib/libpangoft2-1.0.0.dylib (compatibility version
3601.0.0, current version 3601.1.0)
/opt/local/lib/libpango-1.0.0.dylib (compatibility version 3601.0.0,
current version 3601.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 1197.1.1)
/opt/local/lib/libgobject-2.0.0.dylib (compatibility version 3801.0.0,
current version 3801.2.0)
/opt/local/lib/libfontconfig.1.dylib (compatibility version 10.0.0,
current version 10.0.0)
/opt/local/lib/libfreetype.6.dylib (compatibility version 17.0.0,
current version 17.2.0)

/opt/local/lib/libcairo.2.dylib (compatibility version 11203.0.0,
current version 11203.16.0)

/opt/local/lib/libpng15.15.dylib (compatibility version 33.0.0,
current version 33.0.0)
/opt/local/lib/libcroco-0.6.3.dylib (compatibility version 4.0.0,
current version 4.1.0)
/opt/local/lib/libglib-2.0.0.dylib (compatibility version 3801.0.0,
current version 3801.2.0)
/opt/local/lib/libintl.8.dylib (compatibility version 10.0.0, current
version 10.2.0)
/opt/local/lib/libxml2.2.dylib (compatibility version 12.0.0, current
version 12.1.0)

That said I can't figure out how make librsvg link with the dynamic libaries
provided by Racket.

After a while experimenting with automake, pkg-config and configure, I
now have set the environment variable DYLD_LIBRARY_PATH :

DYLD_LIBRARY_PATH=/Users/soegaard/racket-27-oct/racket/native-pkgs/draw-x86_64-macosx/racket/draw;/opt/local/lib

and configures likes this:

./configure --disable-gtk-theme  --disable-gtk-doc --disable-Bsymbolic
LDFLAGS='-L/Users/soegaard/racket-27-oct/racket/native-pkgs/draw-x86_64-macosx/racket/draw/'
LIBRSVG_LIBS='/Users/soegaard/racket-27-oct/racket/native-pkgs/draw-x86_64-macosx/racket/draw/'


Making all in .

  CCLD     librsvg-2.la

Undefined symbols for architecture x86_64:

  "_cairo_append_path", referenced from:
      _rsvg_cairo_render_path in librsvg_2_la-rsvg-cairo-draw.o
      _rsvg_cairo_clip_render_path in librsvg_2_la-rsvg-cairo-clip.o

  "_cairo_clip", referenced from:
      _rsvg_filter_primitive_image_render in librsvg_2_la-rsvg-filter.o
      _rsvg_cairo_add_clipping_rect in librsvg_2_la-rsvg-cairo-draw.o
      _rsvg_cairo_clip in librsvg_2_la-rsvg-cairo-clip.o
     (maybe you meant: _rsvg_cairo_clip)

Using  file  I checked that everything was compiled as 64 bit
binaries - but everything looked ok.

At this point I uninstalled the macports version of Cairo and fetched
cairo-1.10.2 from the Cairo web-site. (I believe it is the version used
by Racket).

Cairo was very easy to build (standard ./configure; make ; make install).
This gives be a new libcairo in /usr/local/lib and include files with
the right version in /usr/local/include.

Building librsvg now complains about Pango. So I fetched
pango-1.29.5 and attempted to build that.

Now I get errors about cairo-gobject.

At this point I ran out of steam.

> If I swap out "libcairo" and try to re-link, then... well, I get a link
> error due to missing support for Cairo XML. But disabling the use of
> Cairo XML lets me link, and then "librsvg-2.2.dylib" has the right
> compatibility version of "libcairo.2.dylib" according to `otool -L`.
>
> I run into other issues trying to use the library because I didn't
> really set things up right. In any case, I think you're on the right
> track, and you just need to make sure that you really link against the
> Racket "libcairo" after all.
>
> To turn "librsvg-2.2.dylib" into something that you can give other Mac
> users to install into their Racket "lib" directory, you'll need to
> adjust the references from the "librsvg-2.2.dylib" to other ".dylib"s.
> You'll want to use `install_name_tool` and "@executable_path/..." paths
> for that. Let me know if you get that far and need more hints.

I experimented a litlle with install_name_tool in the librsvg that
references /opt/local/lib/libcairo. I succeeded in changing it
to the path of Racket's libcairo. Unfortunately it complained
about version incompatibility (the macports one demanded
a newer version than what Racket provides).

The suspect the experiment shows that the compatibility library version
is determined by the header files (I am not sure though).

--
Jens Axel Søgaard


Posted on the users mailing list.