Search code examples
rinstallationcairo

Compile R with Cairo support without X11


I'm trying to compile R 3.1.1 from source with cairo support enabled. I want this because I'm trying to run R on a server which does not have a graphical environment (hence no X11), but still output PNG's.

I tried to configure R with

./configure --with-x=no --with-cairo=yes --with-libpng=yes --enable-R-shlib --prefix=$HOME

Doing this produces an R binary with no png or cairo support (as evidenced by capabilities()). In config.log, there is the following.

configure:31563: checking for X 
configure:31749: result: disabled
configure:32420: result: using X11 ... no
configure:32530: checking whether pkg-config knows about cairo and pango 
configure:32542: result: yes
configure:32576: checking whether cairo including pango is >= 1.2 and works 
configure:32599: gcc -std=gnu99 -o conftest -g -O2 -fpic  -I/usr/local/include  -pthread -I/home/rmccloskey/include/pango-1.0 -I/home/rmccloskey/include/cairo -I/home/rmccl
oskey/include/glib-2.0 -I/home/rmccloskey/lib/glib-2.0/include -I/home/rmccloskey/include/pixman-1 -I/usr/include/freetype2 -I/home/rmccloskey/include/freetype2 -I/home/rmc
closkey/include/libpng16   -L/usr/local/lib64 conftest.c -lrt -ldl -lm  -L/home/rmccloskey/lib -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lpng16 -lz -lcairo   >
&5
conftest.c:232:24: fatal error: cairo-xlib.h: No such file or directory
 #include <cairo-xlib.h>
                        ^     
compilation terminated.

As you can see, configure knows about cairo and pango, and it also knows that I'm not using X11. But it still tries to compile a file requiring cairo-xlib.h? What can I do here?


Solution

  • In the most narrow sense, Cairo appears to require x11 headers.

    In a wider sense, look into the various answers detailing use of the xvfb virtual x11 server -- they allow you headless use.

    Also, you could try building without x11, png, cairo -- and then use one of the two cairo packages from CRAN to create graphs. In Debian/Ubuntu we also have at least the cairoDevice package pre-build for you.