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

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Nov 24 09:32:58 EST 2013

2013/11/17 Matthew Flatt <mflatt at cs.utah.edu>:
> At Sat, 16 Nov 2013 22:16:40 +0100, Jens Axel Søgaard wrote:

> 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 managed to build Cairo and Poppler and get it everything working.
Displaying pdf-files within DrRacket works a charm. As a consequence
I can now use LaTeX to render formulas to pdf, converting the pdf to pict
and use the formulas directly in slideshows and pictures.

Now comes the problem of distributing the relevant libraries.

At first I thought I could build Poppler with the same version of Cairo
as DrRacket and simply distribute the extra binaries, but it turns out
that Poppler needs a libcairo with support for Freetype and FontConfig.

The binaries below contain a tar of a set of libraries which work together.

It was compiled on a x64 machine with OS Mavericks. I used
    MACOSX_DEPLOYMENT_TARGET=10.5
and
   -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk
during for all builds, but help to confirm that the libraries actually works
on other machines than my own.

Inspired by you install-files.rkt I didn't use @executable_path
but used @loader_path.

Since the original goal was a make libpoppler that were compatible
with Racket's libcairo, I have used version numbers of the
various libraries as close the Racket ones as I could.

https://www.dropbox.com/s/hdwbm2nt0fap8bt/soegaard-libs.tar.gz

To test these binaries, place them in the result of

    > (require setup/dirs)
    > (find-lib-dir)
    #<path:/Users/soegaard/racket-nov-24/racket/racket/lib>

To see a pdf-file inside DrRacket run:

#lang racket
(require (planet gcr/pdf-render:2:=2) pict)
(define pdf-file "/Users/soegaard/Downloads/x.pdf")
(if (file-exists? pdf-file)
    (pict->bitmap (page->pict pdf-file))
    "not found")

Note that (page->pict pdf-file) displays an empty snip.

The reason is that DrRacket normally calls the pict not
with a real cairo context, but with a record-dc% and the
recorded operations are then later replayed. Since
the pict from (page->pict pdf-file) calls libpoppler that
calls libcairo, these operations aren't recorded.

A few questions:

  1. Do these binaries work for others than me?
  2. Is it worth looking into getting these binaries working on pre
x64 hardware?
  3. Should I make a set of binaries with new versions of all
libraries in question?
     (While I can remember how things work)

I will write up a detailed description of how I build them and put the sources
on GitHub.

--
Jens Axel Søgaard


Posted on the users mailing list.