MAC Os X R Error "Ld: Warning: Directory Not Found for Option"

ld: Warning: directory not found when attempting to install R package

You seem to be running an outdated version of R. You should install the latest version. What follows is only valid for the latest version of R.

You don't seem to have the Fortran compiler installed. You can get it from CRAN on this page tools. You might also need to install the clang6 compiler available on the same page.

If you do that you should add this

/usr/local/clang6/bin 

to the start of your PATH. You should check that /usr/local/bin is in your path to make the gfortran compiler accessible.

You should also add these lines to your ~/.R/Makevars.

CC=/usr/local/clang6/bin/clang
CXX=/usr/local/clang6/bin/clang++
LDFLAGS =-L/usr/local/clang6/lib

‘ld: warning: directory not found for option’

You need to do this:

  1. Click on your project (targets)
  2. Click on Build Settings
  • if your error includes the -L flag, then delete the values in Library Search Paths
  • if your error includes the -F flag, then delete the values in Framework Search Paths

And regarding the second error, sorry i can't help you out with that one. Hope someone else can help you out.

ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator'

I had a similar issue and solved it by adding -fprofile-instr-generate to Build Settings > Linking > Other Linker Flags

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.



Related Topics



Leave a reply



Submit