RcppArmadillo and gfortran on Mac OS 10.13 High Sierra
These days I’ve been checking the markovchain
R package to handle Markov Chains in R (surprise!) and it looked interesting, so I thought it would be nice to check what’s going on under the hood. I cloned the repository, loaded the project into RStudio and tried to build it, just to see
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [markovchain.so] Error 1
ERROR: compilation failed for package ‘markovchain’
Just to figure out I don’t have /usr/local/gfortran
or anything similar (though XCode, command line tools, etc. are installed).
But hey, I have brew
…
➜ ~ brew install gfortran
Error: No available formula with the name "gfortran"
GNU Fortran is now provided as part of GCC, and can be installed with:
brew install gcc
Ok, let’s get gcc…
➜ ~ brew install gcc
[...a lot of output...]
/usr/local/Cellar/gcc/7.2.0: 1,487 files, 285.0MB, built in 64 minutes 12 seconds`
That was fast! But markovchain
still won’t compile… Let’s check the R documentation for building from source! From the R for Mac OS X FAQ:
If using a CRAN binary install of R the compilers may not be in the same place or have the same names as on the CRAN build machine. Look at file /Library/Frameworks/R.framework/Resources/etc/Makeconf […]
You can either edit that file, or override settings in file ~/.R/Makevars: see the section ‘Customizing package compilation’ of the ‘R Installation and Administration Manual’.
So I just added the following line to ~/.R/Makevars
(since I didn’t have such file, I actually added the line in an empty file):
FLIBS=-L/usr/local/Cellar/gcc/7.2.0/lib/gcc/7
And… * DONE (markovchain)