Problem compiling the ´gridtext´ package in R

Viewed 1932

I am trying to install the ´ggtext´ package in R 3.6.0 which has a dependency on another package called ´gridtext´. After running install.packages("ggtext") I get the error:

grid-renderer.h:61:94: error: no matching function for call to ‘Rcpp::Vector<10, Rcpp::PreserveStorage>::Vector(int, bool&, const GraphicsContext&)’

Trying to install from github results in the same problem. I am trying to do this in a server running CentOS Linux release 7.7.1908.

More detailed error message:

g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG  -I"/home/myuser/R/x86_64-redhat-linux-gnu-library/3.6/Rcpp/include" -I"/home/myuser/R/x86_64-redhat-linux-gnu-library/3.6/testthat/include" -I/usr/local
/include  -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c RcppExports.cpp -o RcppExports.
o
In file included from gridtext_types.h:12:0,
                 from RcppExports.cpp:4:
grid-renderer.h: In member function ‘void GridRenderer::raster(Rcpp::RObject, Length, Length, Length, Length, bool, const GraphicsContext&)’:
grid-renderer.h:61:94: error: no matching function for call to ‘Rcpp::Vector<10, Rcpp::PreserveStorage>::Vector(int, bool&, const GraphicsContext&)’
           NumericVector(1, width), NumericVector(1, height), LogicalVector(1, interpolate, gp)

EDIT: trying install.packages("gridtext", dep = TRUE) results in the following error:

Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lcairo -lfreetype
-----------------------------[ ANTICONF ]-------------------------------
Configuration failed to find Cairo or Freetype2. Try installing:
 * deb: libcairo2-dev (Debian, Ubuntu)
 * rpm: cairo-devel (Fedora, CentOS, RHEL)
 * csw: libcairo_dev (Solaris)
 * brew: cairo (OSX)
If cairo freetype2 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a cairo freetype2.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
---------------------------[ ERROR MESSAGE ]----------------------------
src/tests/sysdeps.c:1:10: fatal error: cairo-ft.h: No such file or directory
 #include <cairo-ft.h>
          ^~~~~~~~~~~~
compilation terminated.
------------------------------------------------------------------------
ERROR: configuration failed for package ‘gdtools’
* removing ‘/home/miguel/R/x86_64-redhat-linux-gnu-library/3.6/gdtools’
ERROR: dependency ‘gdtools’ is not available for package ‘vdiffr’
* removing ‘/home/miguel/R/x86_64-redhat-linux-gnu-library/3.6/vdiffr’

The downloaded source packages are in
        ‘/tmp/RtmpszdI5c/downloaded_packages’
Warning messages:
1: In install.packages("gridtext", dep = TRUE) :
  installation of package ‘gridtext’ had non-zero exit status
2: In install.packages("gridtext", dep = TRUE) :
  installation of package ‘gdtools’ had non-zero exit status
3: In install.packages("gridtext", dep = TRUE) :
  installation of package ‘vdiffr’ had non-zero exit status
> install.packages('ggext', dep=TRUE)

EDIT Update after doing sudo yum install cairo-devel

g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG  -I"/home/miguel/R/x86_64-redh
at-linux-gnu-library/3.6/Rcpp/include" -I"/home/miguel/R/x86_64-redhat-linux-gnu
-library/3.6/testthat/include" -I/usr/local/include  -fpic  -O2 -g -pipe -Wall -
Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-
size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c RcppExports.cpp -o RcppEx
ports.o
In file included from gridtext_types.h:12:0,
                 from RcppExports.cpp:4:
grid-renderer.h: In member function ‘void GridRenderer::raster(Rcpp::RObject, Le
ngth, Length, Length, Length, bool, const GraphicsContext&)’:
grid-renderer.h:61:94: error: no matching function for call to ‘Rcpp::Vector<10,
 Rcpp::PreserveStorage>::Vector(int, bool&, const GraphicsContext&)’
 icVector(1, width), NumericVector(1, height), LogicalVector(1, interpolate, gp)
1 Answers

You g++ version is too low to support c++11, this has been pointed by https://github.com/wilkelab/gridtext/issues/7#issuecomment-646808225.

Use the following command:

sudo yum install centos-release-scl
sudo yum install devtoolset-9
# If you use your non-root account to install packages, 
# remove the sudo and change /root to /home/your_id in the following command
sudo mkdir -p /root/.R
sudo vim /root/.R/Makevars

Add content to the opened file and save it:

CXX11=/opt/rh/devtoolset-9/root/usr/bin/g++ -std=c++11

Reinstall the packages, you will see g++ has been changed to /opt/rh/devtoolset-9/root/usr/bin/g++

> install.packages("gridtext")
Installing package into ‘/usr/lib64/R/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/gridtext_0.1.4.tar.gz'
Content type 'application/x-gzip' length 234461 bytes (228 KB)
==================================================
downloaded 228 KB

* installing *source* package ‘gridtext’ ...
** package ‘gridtext’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/opt/rh/devtoolset-9/root/usr/bin/g++ -std=c++11 -std=gnu++11 -I"/usr/include/R" -DNDEBUG  -I"/usr/lib64/R/library/Rcpp/include" -I/usr/local/include  -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c RcppExports.cpp -o RcppExports.o
Related