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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Nov 16 19:41:14 EST 2013

At Sat, 16 Nov 2013 22:16:40 +0100, Jens Axel Søgaard wrote:
> Welcome to DrRacket, version 5.90.0.10--2013-11-10(53c6658e/d) [3m].
> Language: racket/gui.
> . . ffi-lib: couldn't open "librsvg-2.2.dylib"
> (dlopen(librsvg-2.2.dylib, 6): Library not loaded:
> /opt/local/lib/libcairo.2.dylib
>   Referenced from: /usr/local/lib/librsvg-2.2.dylib
>   Reason: Incompatible library version: librsvg-2.2.dylib requires
> version 11203.0.0 or later, but libcairo.2.dylib provides version
> 11003.0.0)
> 
> This is progress. Racket has now loaded the correct version of librsvg
> - and it even tries to use
> the libcairo that Racket provides (version 1.10.3). Unfortunately the
> include files I used for Cairo
> were for 1.12.3 so I get the incompatible library version error.
> 
> At first I thought that were easy to fix - I just need to get the
> include files for Cairo version 1.10.3
> and recompile librsvg. But ... version 1.10.3 is not a release version
> of Cairo. ( http://cairographics.org/releases/ )
> And now I give up.

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".

The path "/opt/local/lib/libcairo.2.dylib" is an unusual place for the
Racket "libcario". Normally, that would be the MacPorts "libcario".
Did you maybe build "librsvg" with the MacPorts "libcairo", and then
move the Racket "libcairo" in place of the MacPorts one? When I do
that, I get exactly the error that you report.

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.



Posted on the users mailing list.