13

I need to install svglite, but an error comes up saying I need gdtools first, so I try to install gdtools and get the following error:

   > install.packages("gdtools", lib="/usr/local/lib/R/3.4/site-library")
trying URL 'https://cran.rstudio.com/src/contrib/gdtools_0.1.4.tar.gz'
Content type 'application/x-gzip' length 33931 bytes (33 KB)
==================================================
downloaded 33 KB

* installing *source* package ‘gdtools’ ...
** package ‘gdtools’ successfully unpacked and MD5 sums checked
Using PKG_CFLAGS=-I/usr/local/opt/cairo/include/cairo
Using PKG_LIBS=-L/usr/local/opt/cairo/lib -lcairo
** libs
clang++  -I/usr/local/Cellar/r/3.4.1_1/lib/R/include -DNDEBUG -I/usr/local/opt/cairo/include/cairo -I../inst/include/ -I"/usr/local/lib/R/3.4/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include   -fPIC  -g -O2  -c CairoContext.cpp -o CairoContext.o
In file included from CairoContext.cpp:7:
/usr/local/opt/cairo/include/cairo/cairo-ft.h:46:10: fatal error: 'ft2build.h' file not found
#include <ft2build.h>
         ^
1 error generated.
make: *** [CairoContext.o] Error 1
ERROR: compilation failed for package ‘gdtools’
* removing ‘/usr/local/lib/R/3.4/site-library/gdtools’
Warning in install.packages :
  installation of package ‘gdtools’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/2c/2dtnf2fs5z7cy45v5gt32n0m0000gn/T/Rtmpj7APMT/downloaded_packages’

Can anyone help me please?

Laura Harding
  • 131
  • 1
  • 8
  • 1
    The key message here is *'ft2build.h' file not found*. You are missing some library on your computer that the `gdtools` package needs. A search for this on the internet turned up a couple of potentially helpful links [here](https://stackoverflow.com/questions/16826069/osx-10-7-5-fatal-error-ft2build-h-file-not-found) and [here](https://stackoverflow.com/questions/762292/matplotlib-build-problem-error-c1083-cannot-open-include-file-ft2build-h). – lmo Aug 07 '17 at 14:08
  • 1
    I had to install pkg-config and now it works! Thank you – Laura Harding Aug 07 '17 at 15:31
  • 1
    For future viewers, the solution was `brew install pkg-config`. (at least for me) – Nicholas Hayden Apr 27 '18 at 22:55

5 Answers5

9

I had this same problem and the following solution worked for me:

brew install pkg-config brew install cairo

I was then able to successfully install the gdtools and svglite R packages.

bogenton
  • 319
  • 3
  • 12
2

I had the same problem even with cairo and pkg-config installed through Homebrew, and none of the solutions with PKG_CONFIG_PATH worked for me.

But installing GitHub version with devtools did the trick:

devtools::install_github('davidgohel/gdtools')

devtools::install_github("r-lib/svglite")

There must be a reason for devtools to correctly find paths and flags and maybe someone could explain it.

Besides, if you want to keep your GitHub versions updated, you can use the dtupdate R package.

alazarlo
  • 61
  • 2
1

Similar to the answer by @bogenton, installing both cairo and pkgconfig was the solution.

For others using conda instead of brew:

conda install -c anaconda cairo  
conda install -c anaconda pkgconfig
GobiJerboa
  • 175
  • 2
  • 5
1

I had a similar problem. I installed cairo sudo apt-get install libcairo2-dev

Then gdtools installed in R with no problem

Paul
  • 21
  • 1
0

If you're in a conda/anaconda environment:

conda install -c conda-forge pkg-config 
conda install -c conda-forge cairo
conda install -c conda-forge r-svglite

You'll probably already have cairo in a basic conda environment, but try it anyway. This solution worked for me.

Thomas Matthew
  • 2,826
  • 4
  • 34
  • 58