简体   繁体   中英

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?

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

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.

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

In the Rxyz 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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM