0

I am trying a very simple example to use armadillo functions and data types within Rcpp.

I have managed to get Rcpp to generate functions using a call to cppFunction.

But when I try using Armadillo specific stuff, I get what appears to be a compilation error: it appears Rcpp does not find something it needs to create the v function.

Is there a component missing from my environment? I had assumed the installation of RcppArmadillo would take care of everything.

The details are linked below.

library(RcppArmadillo)
# This works:
Rcpp::cppFunction('int g(int n) {
  if (n < 2) return(n);
                  return(g(n-1) + g(n-2)); }')
sapply(0:10, g)
#  [1]  0  1  1  2  3  5  8 13 21 34 55

# This does not:
cppFunction("arma::mat v(arma::colvec a) {
            return a*a.t();}",
            depends="RcppArmadillo")
# 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: *** [sourceCpp_15.so] Error 1
# clang++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppArmadillo/include" -I"/private/var/folders/dh/mlhxstv50wj40rxhftrxhwsm0000gn/T/RtmpLt5yzy/sourceCpp-x86_64-apple-darwin15.6.0-0.12.11" -I/usr/local/include   -fPIC  -Wall -g -O2  -c file198c2cd258d8.cpp -o file198c2cd258d8.o
# 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 sourceCpp_15.so file198c2cd258d8.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
# Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir,  : 
#                      Error 1 occurred building shared library.

sessionInfo()
# R version 3.4.0 (2017-04-21)
# Platform: x86_64-apple-darwin15.6.0 (64-bit)
# Running under: macOS Sierra 10.12.5
# 
# Matrix products: default
# BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
# LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
# 
# locale:
#   [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] RcppArmadillo_0.7.800.2.0 Rcpp_0.12.11             
# 
# loaded via a namespace (and not attached):
#   [1] compiler_3.4.0 tools_3.4.0   
W7GVR
  • 1,990
  • 1
  • 18
  • 24
  • I have found a description of a similar problem (and solution) at "http://thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error/". But I am not sure it is the same problem (the files not found are not the same) and I am a bit queasy from trying and making a mess of my system. Suggestions appreciated. – W7GVR Jun 03 '17 at 21:32
  • Come on, now: `ld: library not found for -lgfortran` has been asked a dozen times and is addressed in your documentation. Start with the Rcpp FAQ. – Dirk Eddelbuettel Jun 03 '17 at 21:44
  • Hi @gvrocha, I've updated my post to include instructions specific to R 3.4.0. The "uninstaller" of the previous approach should appear later in the day. – coatless Jun 04 '17 at 15:22

0 Answers0