6

I'm trying to install the development version of the fst package from github. (I want the development version because it maintains column classes when saving data frames, whereas the current released version does not.)

Initially, installation failed due to lack of OpenMP support. I resolved this (I think) by following the steps here for R 3.4.0 on OSX.

However, now I'm getting the following error: /bin/sh: XX: command not found. I've already set what are supposed to be the appropriate paths in the ~/.R/Makevars file, so I'm not sure what to do next to resolve the error.

Here's my code and output:

First attempt to install fst, before adding OpenMP support

devtools::install_github("fstPackage/fst", ref = "develop")

* installing *source* package ‘fst’ ...
** libs
clang++ -std=gnu++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -fopenmp -I. -Ifstcore -Ifstcore/LZ4 -Ifstcore/ZSTD -Ifstcore/ZSTD/common -Ifstcore/ZSTD/decompress -Ifstcore/ZSTD/compress -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include -fPIC -Wall -g -O2 -c FastStore.cpp -o FastStore.o
clang: error: unsupported option '-fopenmp'
make: *** [FastStore.o] Error 1
ERROR: compilation failed for package ‘fst’

Adding OpenMP support

To add OpenMP support, I followed the steps here for R 3.4.0, including installing gfortran 6.1 from here and clang using the pre-built OSX GUI installer provided here. Then, as instructed, I added the following to my ~/.R/Makevars file:

CC=/usr/local/clang4/bin/clang
CXX=/usr/local/clang4/bin/clang++
CXX11=$CXX
CXX14=$CXX
CXX17=$CXX
CXX1X=$CXX
LDFLAGS=-L/usr/local/clang4/lib

Second attempt to install fst

I then ran the installation code again and got the following error:

devtools::install_github("fstPackage/fst", ref = "develop")

* installing *source* package ‘fst’ ...
** libs
XX -std=gnu++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -fopenmp -I. -Ifstcore -Ifstcore/LZ4 -Ifstcore/ZSTD -Ifstcore/ZSTD/common -Ifstcore/ZSTD/decompress -Ifstcore/ZSTD/compress -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I/usr/local/include -fPIC -Wall -g -O2 -c FastStore.cpp -o FastStore.o
/bin/sh: XX: command not found
make: *** [FastStore.o]
Error 127 ERROR: compilation failed for package ‘fst’

In addition to the errors, I can see that the installation output begins with clang++ -std=gnu++11 ... in the first attempt and XX -std=gnu++11 ... in the second attempt. I'm guessing I need to tell R (or some other program) about the path to clang, but I'm not sure what path is needed or where to put it (and isn't the Makevars file supposed to take care of that?), or whether there are other issues that need to be fixed as well.

Here are some of the particulars about my system:

Macbook Pro, OSX Sierra (version 10.12.5)

RStudio version 1.0.153

R Session Info

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
 [1] httr_1.2.1      compiler_3.4.1  R6_2.2.2        tools_3.4.1     withr_1.0.2    
 [6] curl_2.8.1      memoise_1.1.0   git2r_0.19.0    digest_0.6.12   devtools_1.13.2

UPDATE: Based on @MarkPlotnick's comment, I changed Makevars to the following:

CC=/usr/local/clang4/bin/clang
CXX=/usr/local/clang4/bin/clang++
CXX11=$(CXX)
CXX14=$(CXX)
CXX17=$(CXX)
CXX1X=$(CXX)
LDFLAGS=-L/usr/local/clang4/lib

This resulted in the following error:

* installing source package ‘fst’ ...
** libs /Users/eipi10/.R/Makevars:7: *** Recursive variable `CXX' references itself (eventually). Stop.
ERROR: compilation failed for package ‘fst’

eipi10
  • 91,525
  • 24
  • 209
  • 285
  • 2
    I thought `Makevars` was more like a make file. So the syntax would be `CXX11=$(CXX)` etc. – Mark Plotnick Jul 29 '17 at 18:01
  • 2
    In the time it took you to write (and update) the question you could have copied the `CXX=/usr/local/clang4/bin/clang++` line down four times for the four other assignments -- and would have had time left to brew one nice coffee. – Dirk Eddelbuettel Aug 01 '17 at 21:20
  • For what it is worth, I use `VER=` (ie currently empty), `CCACHE=ccache` and then both `CXX=$(CCACHE) g++$(VER)` and `CXX11=$(CCACHE) g++$(VER)` and that works just fine. – Dirk Eddelbuettel Aug 01 '17 at 21:22
  • 1
    First of all @DirkEddelbuettel, I drink tea and I like it strong, so maybe I would have had time to copy `CXX=/usr/local/clang4/bin/clang++` only one or two times. Second, I only vaguely understand what's going on under the hood with Linux and building packages from source and figuring out what the errors mean, so I just followed the instructions in the post I linked to. I'm going to try your suggestions and I'll report back--after I've brewed a cup of strong tea, that is. – eipi10 Aug 01 '17 at 21:28
  • Mmm, a nice cup of tea in the afternoon...and it's all the more satisfying as I watch the package install from source without errors. Thanks for your help @DirkEddelbuettel. For my edification (if you're willing to take time out from brewing coffee, cutting and pasting paths, or adding functionality to `Rcpp`), can you explain why your first comment worked and why your second comment accomplishes the same goal? (Please feel free to add any of this as an answer.) – eipi10 Aug 01 '17 at 21:42
  • Not entirely sure -- `make` can be hairy. Same variables are more sacred than others; I think because R takes `CXX` as given it may be taken differently here. Or maybe you simply had a another self-referencing definition somewhere... – Dirk Eddelbuettel Aug 01 '17 at 21:47
  • 1
    Or explicitly define CXX11, CXX17, CXX1X as said in https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17331 – Puriney Jan 21 '18 at 20:44

3 Answers3

2

I ran into the issue and figured out the solution based on the comment by @Dirk in "/bin/sh: XX: command not found" error when trying to install development version of R fst package from github

I explicitly set the libraries in .R/Makevars:

CXX11=/usr/local/clang4/bin/clang++
CXX14=/usr/local/clang4/bin/clang++
CXX17=/usr/local/clang4/bin/clang++
CXX1X=/usr/local/clang4/bin/clang++

This worked for me when I encountered this problem, though on my Mac the path to the binary is /Library/Developer/CommandLineTools/usr/bin/clang++)

David LeBauer
  • 31,011
  • 31
  • 115
  • 189
0

Today, I stumbled on this exact problem. Thanks to the advice given by @Mark Plotnick, I came up with a working Makevars file without having to copy/paste the full path of C++ compiler to all other CXX variables. The following Makevars file using the GNU Makefile format works fine:

CC:=/usr/local/clang4/bin/clang
CXX:=/usr/local/clang4/bin/clang++
CXX11:=$(CXX)
CXX14:=$(CXX)
CXX17:=$(CXX)
CXX1X:=$(CXX)
LDFLAGS:=-L/usr/local/clang4/lib

Tested with using devtools::install_github to install packages that require compilation on macOS.

Note: because my Mac system uses the GNU GCC installed from Homebrew, the actual paths of the C and C++ compilers together with the library in my system are:

CC:=/usr/local/bin/gcc-12
CXX:=/usr/local/bin/g++-12
LDFLAGS:=-L/usr/local/Cellar/gcc/12.2.0/lib/gcc/12
-1
/bin/bash: lz4c: command not found

sudo apt-get install liblz4c-tool
leesagacious
  • 182
  • 1
  • 8