Rcpp Warning: "Directory Not Found for Option '-L/Usr/Local/Cellar/Gfortran/4.8.2/Gfortran'"

Rcpp warning: directory not found for option '-L/usr/local/Cellar/gfortran/4.8.2/gfortran'

Short Answer

Just put the path to libgfortran into FLIBS, e.g.

FLIBS=-L/opt/local/lib/gcc48/

Or, symlink the files within to /usr/local/lib/, if you're comfortable with that. This solution is, however, quite brittle as it's easy to forget to update this path if you update gfortran, or move it to a different directory.

Slightly Longer Answer

You can query gfortran for the path to libgfortran.dylib as e.g.

gfortran -print-file-name=libgfortran.dylib

You can just execute this directly in your Makevars file; e.g.

FLIBS = -L`gfortran -print-file-name=libgfortran.dylib | xargs dirname`

Obsolete Long Answer

Try parsing an appropriate FLIBS directly from gfortran output.

First, some background. The /usr/local/Cellar directory is the default path used by homebrew, a package manager for OS X. Think of it as an alternative to macports.

Homebrew now provides gfortran and its associated libraries as part of the gcc package, and so the paths where it installs FORTRAN libraries has now changed. However, these can (in general) be discovered using gfortran -print-search-dirs. For example, on my system,

gfortran -print-search-dirs

will give me

install: /usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/
programs: =/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/bin/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/bin/
libraries: =/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../:/lib/x86_64-apple-darwin14.0.0/4.9.2/:/lib/:/usr/lib/x86_64-apple-darwin14.0.0/4.9.2/:/usr/lib/

Split, and printed with R, I see:

[[1]]
[1] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/"

[[2]]
[1] "/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/"
[2] "/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/"
[3] "/usr/local/Cellar/gcc/4.9.2_1/libexec/gcc/x86_64-apple-darwin14.0.0/"
[4] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/"
[5] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/"
[6] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/bin/x86_64-apple-darwin14.0.0/4.9.2/"
[7] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/bin/"

[[3]]
[1] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/"
[2] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/4.9.2/"
[3] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/"
[4] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../x86_64-apple-darwin14.0.0/4.9.2/"
[5] "/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../"
[6] "/lib/x86_64-apple-darwin14.0.0/4.9.2/"
[7] "/lib/"
[8] "/usr/lib/x86_64-apple-darwin14.0.0/4.9.2/"
[9] "/usr/lib/"

In my case, libgfortran actually lives here:

/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../

And so this is the path we want to pass to FLIBS. But, pulling that out is kind of a pain, so let's just tell FLIBS to use whatever paths are normally used by gfortran:

gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||'

This is nice, but we want the library paths in a format suitable for the compiler; ie, with -L prepended. Let's do that with sed:

gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'

This outputs (split for readability)

-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/
-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/4.9.2/
-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../../../x86_64-apple-darwin14.0.0/lib/
-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../x86_64-apple-darwin14.0.0/4.9.2/
-L/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../
-L/lib/x86_64-apple-darwin14.0.0/4.9.2/
-L/lib/
-L/usr/lib/x86_64-apple-darwin14.0.0/4.9.2/
-L/usr/lib/

All together, this implies that the following should work for you, at least on OS X, but should (in general) work on any platform with gfortran (as long as it's on the PATH):

FLIBS=`gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'`

This isn't perfect, e.g. it will fail if you have spaces in your paths -- if you do, 1) you deserve what you get and 2) it should also be a 'relatively' easy fix.

RcppArmadillo Compile Errors on OS X Mavericks

EDIT: If you're a Homebrew user, you now instead need to use brew install gcc (gfortran is no longer provided separate of gcc), and you can then follow the instructions here to get set up.


You have to symlink the libraries to /usr/local/lib manually:

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

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

(Replace 4.8.2 with whichever version of gfortran you're using from homebrew.)


Alternatively, if you want to keep from modifying /usr/local/lib, you can use

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

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

Rcpp Compilation ERROR: 'clang: error: no such file or directory: '/usr/local/lib/libfontconfig.a'

Your system setup is broken. Neither R nor Rcpp have anything to do with clang (unless you chose clang as your system compiler) or fontconfig.

So start simpler:

R> library(Rcpp)
R> evalCpp("2 + 2")
[1] 4
R>

This just showed that my system has a working compiler R (and Rcpp) can talk to. We can it more explicit:

R> evalCpp("2 + 2", verbose=TRUE)

Generated code for function definition:
--------------------------------------------------------

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
SEXP get_value(){ return wrap( 2 + 2 ) ; }

No rebuild required (use rebuild = TRUE to force a rebuild)

[1] 4
R>

and R is clever enough not to rebuild. We can then force a build

R> evalCpp("2 + 2", verbose=TRUE, rebuild=TRUE)

Generated code for function definition:
--------------------------------------------------------

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
SEXP get_value(){ return wrap( 2 + 2 ) ; }

Generated extern "C" functions
--------------------------------------------------------

#include <Rcpp.h>
// get_value
SEXP get_value();
RcppExport SEXP sourceCpp_0_get_value() {
BEGIN_RCPP
Rcpp::RObject __result;
Rcpp::RNGScope __rngScope;
__result = Rcpp::wrap(get_value());
return __result;
END_RCPP
}

Generated R functions
-------------------------------------------------------

`.sourceCpp_0_DLLInfo` <- dyn.load('/tmp/Rtmpeuaiu4/sourcecpp_6a7c7c8295fc/sourceCpp_2.so')

get_value <- Rcpp:::sourceCppFunction(function() {}, FALSE, `.sourceCpp_0_DLLInfo`, 'sourceCpp_0_get_value')

rm(`.sourceCpp_0_DLLInfo`)

Building shared library
--------------------------------------------------------

DIR: /tmp/Rtmpeuaiu4/sourcecpp_6a7c7c8295fc

/usr/lib/R/bin/R CMD SHLIB -o 'sourceCpp_2.so' --preclean 'file6a7c6d1fc2d6.cpp'
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/tmp/Rtmpeuaiu4" -fpic -g -O3 -Wall -pipe -Wno-unused -pedantic -c file6a7c6d1fc2d6.cpp -o file6a7c6d1fc2d6.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o sourceCpp_2.so file6a7c6d1fc2d6.o -L/usr/lib/R/lib -lR
[1] 4
R>

and on that you see system details on my side (Linux, also using ccache) that will be different for you.

After that, try (Rcpp)Armadillo one-liners and so on.

Error while installing xts package on R

Finally found solution here: http://thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error/

Here it is:

  1. Download gfortran-4.8.2-darwin13.tar.bz2 package from http://r.research.att.com/libs/
  2. Extract the package in ~/ by running sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /

After that I run

R CMD INSTALL xts_0.9.874.tar.gz

and xts installed without errors (BTW, I dowloaded latest xts_0.9.874.tar.gz from https://cran.r-project.org/bin/macosx/tools/ ).

After that quantmod installed without errors. Using this command:

install.packages("quantmod", repos="http://R-Forge.R-project.org", type="source")


Related Topics



Leave a reply



Submit