Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installing data.table on macOS

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.

like image 791
FlyingPickle Avatar asked Oct 15 '25 13:10

FlyingPickle


1 Answers

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
like image 191
jared_mamrot Avatar answered Oct 18 '25 07:10

jared_mamrot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!