RcppArmadillo compiles errors on OS X Mavericks

This is a follow -up to the Rcpp Element-Wise Matrix Multiplication question .

I get a few different errors with RcppArmadillo since upgrading to Mavericks. I have Xcode 5.0.2 and command line tools installed. Also gfortran from Homebrew. But I continue to encounter the error below -

> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) { return(a % b); }", depends="RcppArmadillo") ld: library not found for -lgfortran clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [sourceCpp_18474.so] Error 1 clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include - I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RcppArmadillo/include" -fPIC "-mtune=native -g -O2 -Wall -pedantic -Wconversion" -c fileaf992bfb8f84.cpp -o fileaf992bfb8f84.o clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o sourceCpp_18474.so fileaf992bfb8f84.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -lgfortran /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/lib/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, : Error 1 occurred building shared library. WARNING: The tools required to build C++ code for R were not found. Please install Command Line Tools for XCode (or equivalent). # Contents of Makevars $ cat ~/.R/Makevars CC=clang CXX=clang++ CXXFLAGS="-mtune=native -g -O2 -Wall -pedantic -Wconversion" FLIBS=-lgfortran 

Commenting out FLIBS=-lgfortran does not help and leads to even more error messages -

 > cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) { return(a % b); }", depends="RcppArmadillo") ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64' ld: warning: directory not found for option '-L/usr/local/lib/x86_64' ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3' ld: library not found for -lgfortran clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [sourceCpp_50381.so] Error 1 

Thanks in advance.

Update

Following the recommendations from Kevin and Dirk below, I reinstalled Rcpp, RcppArmadillo and the inline source and updated FLIBS to point to the actual directory. This solved the problem.

 # Update FLIBS in ~/.R/Makevars FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran #Re-Install from source install.packages(c("Rcpp","RcppArmadillo","inline"),type="source") #Restart R 
+6
r xcode rcpp
source share
2 answers

EDIT: If you are a Homebrew user, now you need to use brew install gcc ( gfortran no longer provided separately from gcc ), and you can follow the instructions here to configure.


You should symbolically link the libraries to /usr/local/lib manually:

ln -s /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.* /usr/local/lib/

I thought the brew link gfortran would handle this, but apparently it only symbolizes the gfortran program, not the actual libraries. Therefore, unfortunately, you have to do it yourself.

(Replace 4.8.2 with any version of gfortran that you use from homebrew .)


Alternatively, if you want to refuse to change /usr/local/lib , you can use

 FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran 

in your ~/.R/Makevars , so R knows where to find the gfortran libraries.

+10
source share

I can only suggest you study the numerous streams in the r-sig-mac list , the various answers here on SO, as well as the messages in the rcpp-devel list .

Since your error is due to Fortran failing to bind, you might as well look at the standard Simon U. page , as well as the tools page , it also indicates. AFAIK you must use (older) gfortran 4.2. * From this page with R - but then I am not an OS X user.

Change at the end of 2016. We now have more detailed instructions in section 2.16 of the Rcpp FAQ .

+1
source share

All Articles