3

I have an R package which I am trying to install on a MAC OS (yosemite), and I am getting a linker problem. This is the error that I am getting

clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o File1.so File2.o File3.o File4.o RcppExports.o Utils.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mypackage.so] Error 1
ERROR: compilation failed for package ‘mypackage’

My Makevars file contain:

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

In DESCRIPTION, I have:

Depends:
    R (>= 3.2.0),
    Rcpp,
    RcppArmadillo
LinkingTo: Rcpp, RcppArmadillo

and in R/help.R, I have:

#' @importFrom Rcpp evalCpp
#' @import RcppArmadillo
#' @useDynLib mypackage
NULL

This is not the same issue as this question because I already included the Armadillo dependencies in the header file that is being indluced by the other .cpp files:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <Rmath.h>
#include <RcppArmadillo.h>

// [[Rcpp::depends(RcppArmadillo)]]

Am I missing something? Should the makefile be modified?

Community
  • 1
  • 1
Cauchy
  • 1,677
  • 2
  • 21
  • 30
  • Possible duplicate of [Rcpp error: /usr/bin/ld cannot find -lgfortran](http://stackoverflow.com/questions/23767816/rcpp-error-usr-bin-ld-cannot-find-lgfortran) – nrussell Apr 06 '16 at 18:18
  • @nrussel I don't think so, I already have the RcppArmadillo dependency included. – Cauchy Apr 06 '16 at 20:29
  • IIRC when I had a similar issue I solved it by installing gfortran from research.att, http://stackoverflow.com/a/25912049/471093 – baptiste Apr 06 '16 at 20:55
  • Please see the Rcpp FAQ on this. I was recently updated and expanded. – Dirk Eddelbuettel Apr 06 '16 at 21:23
  • @Cauchy No I was referring to the `ld: library not found for -lgfortran` error. From the FAQ, *"While gfortran is distributed as part of gcc and hence is available by default on most Linux distributions, it is not distributed as part of Apple’s command line tools. So, unfortunately, you’re going to need to install gfortran and its associated libraries yourself."* – nrussell Apr 06 '16 at 21:39
  • @DirkEddelbuettel I will. Is it wrong to put `// [[Rcpp::depends(RcppArmadillo)]]` in a header file and not a .cpp file? – Cauchy Apr 06 '16 at 21:51
  • You don't compile headers, only source files ie `.cpp`. – Dirk Eddelbuettel Apr 07 '16 at 01:55

1 Answers1

8

Fixes:

Easy fix

Open the Terminal from /Applications/Utilities/

Type the following into Terminal

curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /

More time consuming:

Use homebrew or macports to grab gcc which contains gfortran. Change the ~/.R/Makevars. (See the openmp post for more details on the gfortran install with homebrew.)

See:

  1. http://thecoatlessprofessor.com/programming/r-compiler-tools-for-rcpp-on-os-x/
  2. http://thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error/
  3. http://thecoatlessprofessor.com/programming/openmp-in-r-on-os-x/
  4. https://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-FAQ.pdf#page=8
coatless
  • 20,011
  • 13
  • 69
  • 84