[R] R Cairo Installation - Cannot find cairo.h!

2,612 views
Skip to first unread message

Fong Chun Chan

unread,
Apr 28, 2014, 3:26:34 PM4/28/14
to r-h...@r-project.org
Hi,

I am trying to get the R package Cairo installed. I've been successfully in
building the latest version of Cairo library (1.12.16,
http://cairographics.org/) from source and installed into ~/usr/local using

./configure --prefix=/home/fong/usr/local

I set the my CAIRO_LIBS and CAIRO_CLAGS environment variables in my
~/.bashrc:

export CAIRO_LIBS=${HOME}/usr/local/lib
export CAIRO_CFLAGS=${HOME}/usr/local/include

When I try to install Cairo in R using:

install.packages('Cairo')

I get the following error:

checking for pkg-config... /home/fong/usr/local/bin/pkg-config
configure: CAIRO_CFLAGS=/home/fong/usr/local/include/cairo
checking if R was compiled with the RConn patch... no
checking cairo.h usability... no
checking cairo.h presence... no
checking for cairo.h... no
configure: error: Cannot find cairo.h! Please install cairo (
http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.
ERROR: configuration failed for package 'Cairo'

But I can see the cairo.h header in /home/fong/usr/local/include/cairo. I
been trying to scouring the internet for answers, but I can't seem to find
any work for me. If anyone has any suggestions that would be helpful.

Thanks

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] vimcom.plus_0.9-93 setwidth_1.0-3 colorout_1.0-2

loaded via a namespace (and not attached):
[1] tcltk_3.1.0 tools_3.1.0

[[alternative HTML version deleted]]

______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Rolf Turner

unread,
Apr 28, 2014, 8:40:02 PM4/28/14
to Fong Chun Chan, r-h...@r-project.org

Probably not much help to you, but for what it's worth:

* on my system cairo.h is in /usr/include/cairo

Perhaps the CAIRO flags that you set are not adequately guiding the search.

* you need to have the *development* version of cairo installed; on my
system (Fedora 17) I do:

sudo yum install cairo-devel.x86_64

to effect this.

* I believe that to get cairo to fly properly you also need to have
(the development version of) *pango* installed. On my system I do

sudo yum install pango-devel.x86_64

to effect this.

* I don't know how (or even if it is possible) to get yum to install
packages to a "custom" location --- as you would apparently need to do,
since you have created a custom ".../usr/local" under your home directory.

* I was under the impression that to get cairo to fly one needs to do

./configure --with-cairo

All of the foregoing may be a red herring, off the point and have
nothing to do with the problem that you are having. I don't really know
what I'm doing. I just follow recipes. :-) Good luck.

cheers,

Rolf Turner

Peter Langfelder

unread,
Apr 28, 2014, 9:36:52 PM4/28/14
to Fong Chun Chan, r-help
Make sure you have cairo-devel installed, and remove the lines

export CAIRO_LIBS=${HOME}/usr/local/lib
export CAIRO_CFLAGS=${HOME}/usr/local/include

from your .bashrc file. If you have cairo-devel installed normally,
the headers should be found with default settings of all search paths.
The settings you have are, to the best of my somewhat limited
knowledge, wrong - you need to prefix each directory with an
appropriate compiler flags (-L for library directories, and -I for
include directories). Anyway, as I said, 1. install cairo-devel using
your package manager, and 2. remove the two lines from .bashrc.

Peter

Fong Chun Chan

unread,
Apr 28, 2014, 10:14:27 PM4/28/14
to Peter Langfelder, r-help
Hi Peter,

Thanks for the reply. I don't have access to the package manager
unfortunately as I am working on a cluster where I don't have admin. So
everything has to installed into my ~/export CAIRO_LIBS=-L${HOME}/usr/local/
lib
export CAIRO_CFLAGS=-I${HOME}/usr/local/include
/local. I tried looking into homebrew/linuxbrew, but the gcc compiler
(4.1.2) is not suitable for linuxbrew and installing a new gcc compiler
isn't a simply endeavor from source.

I installed cairo from source specifically the
http://cairographics.org/releases/cairo-1.12.16.tar.xz download. What is
this cairo-devel you are referring to? It seems to be something related to
using the package manager?

In any case, your second point about the "-L for library directories, and
-I for
include directories" was actually useful. Rather than remove those lines
(as that didn't help), I modified my ~/.bashrc a bit (I am also limited in
my understanding paths)

export CAIRO_LIBS=-L${HOME}/usr/local/lib
export CAIRO_CFLAGS=-I${HOME}/usr/local/include

This actually got around that issue! But now I've run into another issue:

checking for pkg-config... /home/fong/usr/local/bin/pkg-config
configure: CAIRO_CFLAGS=-I/home/fong/usr/local/include/cairo
checking if R was compiled with the RConn patch... no
checking cairo.h usability... yes
checking cairo.h presence... yes
checking for cairo.h... yes
checking for PNG support in Cairo... yes
checking for ATS font support in Cairo... no
configure: CAIRO_LIBS=-L/home/fong/usr/local/lib
checking for library containing deflate... -lz
checking whether Cairo programs can be compiled... configure: error: Cannot
compile a simple Cairo program. See config.log for details.
ERROR: configuration failed for package 'Cairo'


Fong Chun Chan

unread,
Apr 28, 2014, 11:16:25 PM4/28/14
to Peter Langfelder, r-help
Thanks Peter. From the config.log file, the issue appears to occur here at
the "*/home/fong/Cairo/conftest.c:28: undefined reference to
`cairo_create'"*


-----

configure:3631: gcc -std=gnu99 -o conftest -g -O2
-I/home/fong/usr/local/include/cairo conftest.c -lz
-L/home/fong/usr/local/lib >&5
configure:3631: $? = 0
configure:3648: result: -lz
configure:3657: checking whether Cairo programs can be compiled
configure:3671: gcc -std=gnu99 -o conftest -g -O2
-I/home/fong/usr/local/include/cairo conftest.c -lz
-L/home/fong/usr/local/lib >&5
/tmp/ccIr2WlB.o: In function `main':
*/home/fong/Cairo/conftest.c:28: undefined reference to `cairo_create'*
collect2: ld returned 1 exit status
configure:3671: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "Cairo"
| #define PACKAGE_TARNAME "cairo"
| #define PACKAGE_VERSION "1.3"
| #define PACKAGE_STRING "Cairo 1.3"
| #define PACKAGE_BUGREPORT "Simon....@r-project.org"
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_WAIT_H 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_STRING_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_UNISTD_H 1
| /* end confdefs.h. */


On Mon, Apr 28, 2014 at 7:50 PM, Peter Langfelder <
peter.la...@gmail.com> wrote:

> On Mon, Apr 28, 2014 at 7:14 PM, Fong Chun Chan <fongch...@gmail.com>
> wrote:
> > Hi Peter,
> >
> > Thanks for the reply. I don't have access to the package manager
> > unfortunately as I am working on a cluster where I don't have admin. So
> > everything has to installed into my ~/export
> > CAIRO_LIBS=-L${HOME}/usr/local/lib
> > export CAIRO_CFLAGS=-I${HOME}/usr/local/include
> > /local. I tried looking into homebrew/linuxbrew, but the gcc compiler
> > (4.1.2) is not suitable for linuxbrew and installing a new gcc compiler
> > isn't a simply endeavor from source.
>
> I see - in that case I think you are on the right track.
>
> >
> > I installed cairo from source specifically the
> > http://cairographics.org/releases/cairo-1.12.16.tar.xz download. What is
> > this cairo-devel you are referring to? It seems to be something related
> to
> > using the package manager?
>
> If you install from source, you (usually) also get the development
> files (the content of cairo-devel) by default.
>
> >
> > In any case, your second point about the "-L for library directories,
> and -I
> > for
> > include directories" was actually useful. Rather than remove those lines
> (as
> > that didn't help), I modified my ~/.bashrc a bit (I am also limited in my
> > understanding paths)
> >
> > export CAIRO_LIBS=-L${HOME}/usr/local/lib
> > export CAIRO_CFLAGS=-I${HOME}/usr/local/include
> >
> > This actually got around that issue! But now I've run into another issue:
> >
> > checking for pkg-config... /home/fong/usr/local/bin/pkg-config
> > configure: CAIRO_CFLAGS=-I/home/fong/usr/local/include/cairo
> > checking if R was compiled with the RConn patch... no
> > checking cairo.h usability... yes
> > checking cairo.h presence... yes
> > checking for cairo.h... yes
> > checking for PNG support in Cairo... yes
> > checking for ATS font support in Cairo... no
> > configure: CAIRO_LIBS=-L/home/fong/usr/local/lib
> > checking for library containing deflate... -lz
> > checking whether Cairo programs can be compiled... configure: error:
> Cannot
> > compile a simple Cairo program. See config.log for details.
> > ERROR: configuration failed for package 'Cairo'
>
> If you look at the config.log file and post the releavant part (don't
> post the whole thing, it's huge), I (or R compiling experts) can try
> to help you more.
>
> Peter

Peter Langfelder

unread,
Apr 29, 2014, 12:34:44 AM4/29/14
to Fong Chun Chan, r-help
I **think** the linker is missing a directive to actually link in the
cairo library. Try adding -lcairo to the LIB flags, something like

export CAIRO_LIBS='-L${HOME}/usr/local/lib -lcairo'

or simply

export CAIRO_LIBS=-l${HOME}/usr/local/lib/libcairo.so

I am not 100% sure of the syntax, but this may work.

Note that my pkg-config gives me this for cairo:

$ pkg-config --cflags --libs cairo
-I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1
-I/usr/include/freetype2 -I/usr/include/libpng15 -I/usr/include/libdrm
-lcairo

There are many more -I directives than what you had, but I'm not sure
if all of it is really necessary. if your configure or compilation
fail, it is something to keep in mind.

HTH,

Peter

On Mon, Apr 28, 2014 at 8:16 PM, Fong Chun Chan <fongch...@gmail.com> wrote:
> Thanks Peter. From the config.log file, the issue appears to occur here at

> the "/home/fong/Cairo/conftest.c:28: undefined reference to `cairo_create'"


>
>
> -----
>
> configure:3631: gcc -std=gnu99 -o conftest -g -O2
> -I/home/fong/usr/local/include/cairo conftest.c -lz
> -L/home/fong/usr/local/lib >&5
> configure:3631: $? = 0
> configure:3648: result: -lz
> configure:3657: checking whether Cairo programs can be compiled
> configure:3671: gcc -std=gnu99 -o conftest -g -O2
> -I/home/fong/usr/local/include/cairo conftest.c -lz
> -L/home/fong/usr/local/lib >&5
> /tmp/ccIr2WlB.o: In function `main':

> /home/fong/Cairo/conftest.c:28: undefined reference to `cairo_create'

______________________________________________

Fong Chun Chan

unread,
Apr 29, 2014, 12:55:36 PM4/29/14
to Peter Langfelder, r-help
Hi Peter,

Unfortunately neither of the modifications to the LIB flag worked. I tried:

export CAIRO_LIBS='-L${HOME}/usr/local/lib -lcairo'

This actually gave me an error like this:

.....
configure: CAIRO_CFLAGS=-I/home/fong/usr/local/include/cairo
checking if R was compiled with the RConn patch... no
checking cairo.h usability... yes
checking cairo.h presence... yes
checking for cairo.h... yes
checking for PNG support in Cairo... yes
checking for ATS font support in Cairo... no
configure: CAIRO_LIBS=-L${HOME}/usr/local/lib -lcairo
checking for library containing deflate... none required
checking whether Cairo programs can be compiled... yes
checking whether cairo_image_surface_get_format is declared... no
checking for FreeType support in cairo... yes
checking whether FreeType needs additional flags... yes
checking whether pkg-config knows about fontconfig or freetype2... yes
checking whether additional flags work... no
configure: error: Cannot use cairo-ft backend, although cairo claims it is
working. Please check your caito installation and/or update cairo if
necessary or set CAIRO_CFLAGS/CAIRO_LIBS accordingly.
ERROR: configuration failed for package 'Cairo'
* removing '/home/fong/usr/local/lib64/R/library/Cairo'
* restoring previous '/home/fong/usr/local/lib64/R/library/Cairo'

I then tried to modify the CAIRO_LIBS like this:

export CAIRO_LIBS=-I${HOME}/usr/local/lib/libcairo.so

And this gave me this error:

.....
configure: CAIRO_CFLAGS=-I/home/fong/usr/local/include/cairo
checking if R was compiled with the RConn patch... no
checking cairo.h usability... yes
checking cairo.h presence... yes
checking for cairo.h... yes
checking for PNG support in Cairo... yes
checking for ATS font support in Cairo... no
configure: CAIRO_LIBS=-I/home/fong/usr/local/lib/libcairo.so
checking for library containing deflate... no
checking whether Cairo programs can be compiled... configure: error: Cannot
compile a simple Cairo program. See config.log for details.
ERROR: configuration failed for package 'Cairo'
* removing '/home/fong/usr/local/lib64/R/library/Cairo'
* restoring previous '/home/fong/usr/local/lib64/R/library/Cairo'

My pkg-config command:

>> pkg-config --cflags --libs cairo -I/home/fong/usr/local/include/cairo
-I/home/fong/usr/local/include/pixman-1
-I/home/fong/usr/local/include/freetype2
-I/home/fong/usr/local/include/libpng16 -L/home/fong/usr/local/lib -lcairo

I appear to be missing glib and libdrm which you have. Perhaps I should try
to install that?

Thanks,



On Mon, Apr 28, 2014 at 9:34 PM, Peter Langfelder <
[[alternative HTML version deleted]]

Fong Chun Chan

unread,
Apr 29, 2014, 2:09:45 PM4/29/14
to r-help
For anyone who has these issues, I eventually recognized that the issue had
to do with the fact the mine cairo was not being compiled with freetype
support. I had to recompile cairo with --enable-ft=yes.

Also removed the setting of the CAIRO_LIBS and CAIRO_CLAGS environment
variables in my ~/.bashrc as that was likely unnecessary step as set due to
confusion.

After doing this, running install.packages(Cairo) worked. Hope this helps
anyone having this issue.

Jose-Marcio Martins

unread,
Apr 30, 2014, 7:53:18 AM4/30/14
to Fong Chun Chan, r-h...@r-project.org

Hi,

On 04/28/2014 09:26 PM, Fong Chun Chan wrote:
>
> ./configure --prefix=/home/fong/usr/local
>
> I set the my CAIRO_LIBS and CAIRO_CLAGS environment variables in my
> ~/.bashrc:
>
> export CAIRO_LIBS=${HOME}/usr/local/lib
> export CAIRO_CFLAGS=${HOME}/usr/local/include

maybe

export CAIRO_LIBS=-L${HOME}/usr/local/lib
export CAIRO_CFLAGS=-I${HOME}/usr/local/include

Regards,

José-Marcio
Reply all
Reply to author
Forward
0 new messages