Mac OS X R error "ld: warning: directory not found for option"
You need to modify the ~/.R/Makevars
file. For a greater overview of this see: https://cran.r-project.org/doc/manuals/r-release/R-admin.html#OS-X-packages
Alternatively, this has been answered before in a bit more depth by @kevin-ushey in Rcpp warning: "directory not found for option '-L/usr/local/Cellar/gfortran/4.8.2/gfortran'".
What is happening is your code is not being run under gcc
instead it is being forwarded to clang
You will need to change your compile statements in ~/.R/Makevars/
to gcc
using:
VER=-5.3.0 CC=gcc$(VER)CXX=g++$(VER)CFLAGS=-mtune=native -g -O2 -Wall -pedantic -WconversionCXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -WconversionFLIBS=-L/usr/local/Cellar/gcc/5.3.0/lib/gcc/5
This assumes you have already installed gcc
via homebrew under:
brew install gcc
(gfortran ships with gcc in brew now)
Incorporating previous solutions with additional help from the comments, the following solution has worked for me on Mac OS X High Sierra.
Create/edit ~/.R/Makevars
with the following contents:
VER=-8CC=gcc$(VER)CXX=g++$(VER)CXX11=g++$(VER)CXX14=g++$(VER)CXX17=g++$(VER)CFLAGS=-mtune=native -g -O2 -Wall -pedantic -WconversionCXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -WconversionFLIBS=-L/usr/local/Cellar/gcc/8.2.0/lib/gcc/8
Note, I am using homebrew and have gcc version 8.2.0 installed.
From http://thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error/ you can fix this by downloading the optional gfortran libraries from http://r.research.att.com/libs/ and extracting them. To do this on the command line
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /