3

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?

3 Answers 3

4

I've been able to make this work with CentOS-6.5 and R-3.1.2. I had to yum install cairo and pango first. Here is my configure command:

./configure --with-recommended-packages=no --without-x --with-cairo --with-libpng --with-libtiff --with-jpeglib --enable-R-shlib

2

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.

4
  • 2
    Cairo doesn't require X11 headers. I successfully built Cairo without X11 headers. The issue is that, for some reason, R is requiring Cairo to have been built with Xlib support, despite the --with-x=no flag to configure.
    – rmccloskey
    Oct 8, 2014 at 19:20
  • There is no point in complaining to me about it. If you think the world needs this, prepare a patch and send it to R Core -- else there may be a remaining dependency on x11 font metrics or something like it. I showed you several ways in which you can create graphs even when you work on a headless machine, so I consider the whole point mostly moot. But your mileage may of course vary. Oct 8, 2014 at 19:22
  • 2
    Thanks. I apologise, I wasn't complaining, but rather I thought you misunderstood my question. Unfortunately I'm running somebody else's code so other packages aren't an option. I guess I'll look into xvfb, thanks.
    – rmccloskey
    Oct 9, 2014 at 1:34
  • 1
    No worries, and yes, xvfb should help you. I think I answered a few questions about it on here over the years too, see eg this old one. You want to wrap your script in xvfb-run. Oct 9, 2014 at 1:41
2

I have the exact some problem. I solved this by using the very hackish way below.

In the R.x.y.z src directory, edit the configure file. There is the line:

#include <cairo-xlib.h>

I simply removed this line. And then run this file and make. Everything works for me. My cairo is compiled with out x11 support. Because I am on a shared RHEL6 box. I do everything without root. The purpose I do this is to make R work with Jupyter notebook. In addition to this, I also need to add options(bitmapType='cairo') in $HOME/.Rprofile. This Link is very helpful.

By doing all these hacks, everything works for me now. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.