8

I recently needed to install R 3.2 to get a package from Bioconductor working, but after I installed, I get the following error:

[16:16:11 20] $ r
dyld: Library not loaded: /usr/local/lib/gcc/4.9/libgfortran.3.dylib
  Referenced from: /usr/local/Cellar/r/3.2.0/R.framework/Versions/3.2/Resources/lib/libR.dylib
  Reason: image not found
Trace/BPT trap: 5

Sure enough, brew was set to use gcc 5, so I told brew to use the 4.9 version

brew switch gcc 4.9

which got R running, but then R would fail in the middle of a package install (specifically when I ran biocLite('DESeq2').

Since then, I have tried a number of things, including trying to install gcc 4.8 (but I can't seem to get R to use it, even via ~/.R/Makevars). Even if 4.9 is not installed, R insists on calling the path shown above.

The windows version of R seems to say 4.9 does not work with 3.2:

R-devel temporarily used a new toolchain based on 4.9.2 gcc, put together by Duncan Murdoch using build scripts written by a contractor. However, there were too many incompatibilities with existing code, and this toolchain will not be used for R 3.2.0. See notes for details on building and testing the new toolchain.

Any help would be greatly appreciated!

Edit: I tried installing from source, as suggested by @lmw., but it fails:

[11:27:55 2] $ brew install r --build-from-source
==> Installing r from homebrew/homebrew-science
==> Installing r dependency: gcc
==> Downloading http://ftpmirror.gnu.org/gcc/gcc-5.1.0/gcc-5.1.0.tar.bz2
######################################################################## 100.0%
curl: (28) Resolving timed out after 5542 milliseconds
Trying a mirror...
==> Downloading https://ftp.gnu.org/gnu/gcc/gcc-5.1.0/gcc-5.1.0.tar.bz2
######################################################################## 100.0%
==> Patching
patching file gcc/jit/Make-lang.in
==> ../configure --build=x86_64-apple-darwin14.3.0 --prefix=/usr/local/Cellar/gcc/5.1.0 --libdir=/usr/local/Cellar/gc
==> make bootstrap
==> make install
==> Caveats
GCC has been built with multilib support. Notably, OpenMP may not work:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60670
If you need OpenMP support you may want to
  brew reinstall gcc --without-multilib
==> Summary
  /usr/local/Cellar/gcc/5.1.0: 1351 files, 248M, built in 32.5 minutes
==> Installing r
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> Downloading http://cran.rstudio.com/src/base/R-3/R-3.2.0.tar.gz
######################################################################## 100.0%
==> Patching
patching file src/modules/lapack/vecLibg95c.c
==> ./configure --prefix=/usr/local/Cellar/r/3.2.0_1 --with-libintl-prefix=/usr/local/opt/gettext --enable-memory-pro
==> make
** installing vignettes
** testing if installed package can be loaded
* DONE (survival)
make[1]: *** [recommended-packages] Error 2
make: *** [stamp-recommended] Error 2

READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/homebrew):
  https://github.com/homebrew/homebrew-science/issues

Edit 2: Just for the fun of it, I tried installing r without the --build-from-source option, and it worked. See my solution below. (I think building from source may have fixed the issue with the gcc 5 upgrade, which got things working. I am not going to try it (things are finally working again...why screw with it?), but I wonder if I could remove the variables I set in ~/.R/Makevars (again, see solution below).

muppetjones
  • 296
  • 3
  • 14

3 Answers3

3

Rebuilding R from source fixes the same problem for me.

brew reinstall r --build-from-source

LmW.
  • 1,364
  • 9
  • 16
  • Trying it now, but it seems to be stuck at the download...maybe it's compiling? Hopefully this works! Thanks! – muppetjones May 22 '15 at 15:47
  • The reinstall failed (I think there were other issues), but I removed `r` and tried to install with the `--build-from-source` option, which failed. (See edit in question). I do, however, think that building from source caused one of the dependencies to build from source (I don't have the command line output...things crashed, I restarted), which I think fixed some of the problems related to the gcc upgrade. If your answer turns out to be the step that fixed things, I'll choose your answer--let me know! – muppetjones May 22 '15 at 18:03
1

This was resolved by this commit, with new bottles for R. Make sure you brew update and brew upgrade r.

ianml
  • 772
  • 5
  • 9
  • Good to know! I wonder why this didn't work earlier, though...I was updating and upgrading this morning, but it didn't work. As what I have is working, I probably won't do this just yet...just in case =). Thanks!! – muppetjones May 22 '15 at 21:03
  • Also, it's possible that the commit is the reason why things started working...is there a way to tell whether or not it's because of what I did versus the commit? On the one hand, I don't want to select your answer as the solution as it's less a solution and more of a "it's fixed!", but at the same time, I don't want to choose another answer if the reason things are working is because of the commit. – muppetjones May 22 '15 at 21:06
  • If you reinstalled R and it was 'poured' from the bottle into `/usr/local/Cellar/r/3.2.0_1` then you're using the latest formula revision. Rebuilding from source should also fix things, although the revision (which adds the _1) will still trigger an upgrade (see `brew outdated`). – ianml May 22 '15 at 21:20
  • The issue I have is very similar but does not seem to be resolved this way. – RichMeister Jul 19 '16 at 22:46
  • To explain: (Comment edit timed out): I tried brew update followed by brew upgrade r, but I think maybe its still missing a library level? When I run R it wants to use a library level called "6" but there is only a library level "5." I get dyld: Library not loaded: /usr/local/opt/gcc/lib/gcc/6/libgfortran.3.dylib. But this does exist under "5." That is, there is a /usr/local/opt/gcc/lib/gcc/5/libgfortran.3.dylib (but nothing under /6/. – RichMeister Jul 19 '16 at 22:52
0

This is not a complete fix (it uses an older gcc version), but it get's me running again:

  1. brew tap homebrew/homebrew-versions
  2. brew install gcc48
  3. brew install r
    • NOTE: I ran brew install r --build-from-source (reinstall did not work), which rebuilt something, but not r (it failed). It may be partially responsible for this working. Please let me know if it is! I'd like to give @lmw credit if his answer is the reason this worked.
  4. Edit ~/.R/Makevars and add the following lines (edit paths as necessary):

    CC=/usr/local/Cellar/gcc48/4.8.4/bin/gcc-4.8
    CXX=/usr/local/Cellar/gcc48/4.8.4/bin/g++-4.8
    CFLAGS=-std=c99
    
  5. Run r.

  6. (If you're trying to install bioconductor)

    source("http://bioconductor.org/biocLite.R")
    biocLite()
    
muppetjones
  • 296
  • 3
  • 14