4

I need to install data.table 1.12.0 (specifically) on macOS 11.1.

I am getting an error:

clang: error: unsupported option '-fopenmp'
make: *** [assign.o] Error 1

I have followed the directions in https://github.com/Rdatatable/data.table/wiki/Installation#openmp-enabled-compiler-for-mac but still unable to get it to work. R 3.6.1.

I also tried a R CMD install and got the same error:

R CMD install data.table_1.12.0.tar.gz 
* installing to library ‘/Users/XXX/Library/R/3.6/library’
* installing *source* package ‘data.table’ ...
** package ‘data.table’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fopenmp -fPIC  -Wall -g -O2  -c assign.c -o assign.o
clang: error: unsupported option '-fopenmp'
make: *** [assign.o] Error 1
ERROR: compilation failed for package ‘data.table’
* removing ‘/Users/XXX/Library/R/3.6/library/data.table’

Update: Seems to be an issue install latest data.table from CRAN for me as well, so its not restricted to 1.12.0 apparently.

FlyingPickle
  • 1,047
  • 1
  • 9
  • 19
  • While none of the answers have been *accepted*, they have been upvoted by others, suggesting their merit. See https://stackoverflow.com/q/43555410/3358272 – r2evans Jan 23 '21 at 16:01

2 Answers2

6

NB. This solution works with Intel processors (not Apple M1 silicon)

These are the steps I used to install data.table from source with multithreading/openMP enabled (originally described in https://stackoverflow.com/a/65334247/12957340):

  1. Reinstall xcode command line tools (even if it says "up to date")
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
  1. Install gcc & llvm via Homebrew (instructions for installing Homebrew) or, if you already have gcc/llvm installed via Homebrew, skip to the next step
# This can take several hours
brew install gcc
brew install llvm
  1. Once you have gcc & llvm installed via Homebrew:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm
  1. Link some headers into /usr/local/include
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/

# You can safely ignore warnings like this:
#ln: /usr/local/include//tcl.h: File exists
#ln: /usr/local/include//tclDecls.h: File exists
#ln: /usr/local/include//tclPlatDecls.h: File exists
#ln: /usr/local/include//tclTomMath.h: File exists
#ln: /usr/local/include//tclTomMathDecls.h: File exists
#ln: /usr/local/include//tk.h: File exists
#ln: /usr/local/include//tkDecls.h: File exists
#ln: /usr/local/include//tkPlatDecls.h: File exists
  1. Install the gmp library:
brew install gmp
  1. Create a new ~/.R/Makevars file (if you already have a ~/.R/Makevars file, save it in a different directory (away from ~/.R/)) and include only these lines in the file:
LOC=/usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11 = $(LOC)/bin/g++ -fopenmp

CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/include

FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++
  1. Compile data.table from source in R/Rstudio
install.packages("data.table", type = "source")

# To check whether it installed correctly, run:
library(data.table)
  1. If your package fails to compile, a couple of SO users have had to install a fresh gfortran (re: https://stackoverflow.com/a/65334247/12957340), which you can download from https://github.com/fxcoudert/gfortran-for-macOS/releases
jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
0

here has been my approach

basically you have to download clang and llvmorg

curl -SL https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz \
   | tar -xJC . && \
   mv clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04 clang_10.0.0 && \
   echo 'export PATH=/clang_10.0.0/bin:$PATH' >> ~/.bashrc && \
   echo 'export LD_LIBRARY_PATH=/clang_10.0.0/lib:$LD_LIBRARY_PATH' >> ~/.bashrc

and make sure they are listed in you PATH and LD_LIBRARY_PATH

then get the datatable and build from the source

git clone https://github.com/h2oai/datatable.git && \
   cd datatable && \
   make build && \
   python -m pip install ../datatable/

make sure you are using the right Python

Areza
  • 5,623
  • 7
  • 48
  • 79