I'm trying to install packages in R that depend on libgfortran, but I keep getting this error:
dyld: Library not loaded: /usr/local/opt/gcc/lib/gcc/7/libgfortran.4.dylib
Referenced from: /usr/local/Cellar/r/3.4.3_1/lib/libR.dylib
Reason: image not found
I have gfortran installed through homebrew gcc:
❯❯ readlink `which gfortran`
../Cellar/gcc/8.2.0/bin/gfortran
There's a libgfortran available at /usr/local/opt/gcc/lib/gcc/8/libgfortran.5.dylib, but this is not the one R is looking for. How do I convince R to look for gcc 8 instead of gcc 7?
"How do I convince R to look for gcc 8 instead of gcc 7?"
You should not do that! Those libraries are NOT compatible, that's why soname is changed. The ABI is different. You need the correct version of GCC which was used to compile your R package. See very similar (but Linux) questions and answers like R v3.4.0-2 unable to find libgfortran.so.3 on Arch How to install libgfortran.so.4 on ubuntu 16.06
You really need the compatible library or update your R to a version that uses GCC 8.
Related
Trying to figure out how to get a new version of gsl recognized by R. I added the last two lines to the Makevars file because I couldn't get the system to recognize this new version as default.
CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14=g++ -std=c++14
CXX_STD=CXX14
GSL_CFLAGS=-I/usr/local/gsl/2.4/include
GSL_LIBGS=-L/usr/local/gsl/2.4/lib -lgsl -lgslcblas -lm
However, when I go to install, you can see part of it is calling 2.4 and part isn't.
Note that according to gsl's github page, the error I'm getting is consistent with a 1.X version of gsl.
Any help (1) getting centos to recognize the new gsl version or (2) just getting R to use it to compile the gsl package would be greatly appreciated!
The problem is that gsl 2.5>= is needed. The error message is not updated, see
https://github.com/RobinHankin/gsl/issues/18
I am repeatedly encountering the following error
/usr/bin/ld: cannot find -lgfortran
when trying to install a lot of r-packages (e.g. igraph, ergm, blockmodels, and I guess every package that requires gcc and fortran in some way or another)
I run R on Ubuntu Trusty, and I have recently upgraded R from 3.1.0 to 3.3.1.
When on 3.1.0, I had been able to install igraph and ergm (and others) without any problem, but not blockmodels.
I have checked for the presence of libgfortran on my system: it is there. Actually there is more than one version of it (3, 4.7, 4.8) and also libgfortran-dev is installed (multiple versions as well)
Any idea of what is going on?
Thank you for any advice.
In Arch Linux, the gfortran package is named gcc-fortran. To install it:
sudo pacman -S gcc-fortran
I'm trying to build the R openssl package and link it to an openssl library that is a newer version than the one in the systemwide lib64 directory.
The Makevars file simply has:
KG_CPPFLAGS=#cflags#
PKG_LIBS=#libs#
I can specify my local library by passing a custom library path in the configure script. But when I issue R CMD INSTALL, the linking command begins with
gcc -std=gnu99 -shared -L/usr/local/lib64 -o openssl.so [...objects...] -Lmy/path/here -lssl -lcrypto
As a result, the linker finds the wrong library (the one in /usr/local/lib64) instead of mine.
How do I adjust the linking command so that it looks for the library first in my directory, instead of the system folder.
(Background: I don't have root access and this older version of CentOS (5) doesn't support openssl v1, so I built v1 myself just to compile the R package. But I'm stuck at the linking stage due to whatever magic is happening by R CMD INSTALL.)
I solved this by passing arguments to R CMD INSTALL. I.e.:
R CMD INSTALL . --configure-vars="INCLUDE_DIR=$HOME/local/include LIB_DIR=$HOME/local/lib64"
But this varies for each package. There's no general solution.
Instead, read config and src/Makefile.in.
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).
Rebuilding R from source fixes the same problem for me.
brew reinstall r --build-from-source
This was resolved by this commit, with new bottles for R. Make sure you brew update and brew upgrade r.
This is not a complete fix (it uses an older gcc version), but it get's me running again:
brew tap homebrew/homebrew-versions
brew install gcc48
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.
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
Run r.
(If you're trying to install bioconductor)
source("http://bioconductor.org/biocLite.R")
biocLite()
I made a simple fortran routine
subroutine add(x,y)
real(8) :: x,y
y = x + 3
end subroutine
saved as test.f90.
I compile with
gfortran -shared test.f90 -o test.so
In R (in the same directory), I use
dyn.load('test.so')
but it gives me this error:
Error in dyn.load("test.so") :
unable to load shared object '/Users/Steven/Documents/PhD/npsR/test.so':
dlopen(/Users/Steven/Documents/PhD/npsR/test.so, 6): Symbol not found: ___addtf3
Referenced from: /usr/local/gfortran/lib/libquadmath.0.dylib
Expected in: /Library/Frameworks/R.framework/Resources/lib/libgcc_s.1.dylib
in /usr/local/gfortran/lib/libquadmath.0.dylib
Does anyone know why? I'm using mac osx Lion, with R v2.15.0 and gfortran 4.6.2.
Thank you!
Unless you really understand what you're doing, you should use gfortran that comes with R tools. The missing symbol in libgcc isn't surprising since you're trying to run code compiled with a 4.6 gfortran in a 4.2 runtime environment.
You can only use the gfortran version that was used to build R.
Since you are on Lion and presumably have Xcode installed you can get the appropriate version of gfortran from here: http://r.research.att.com/tools/
Go to section: "Apple Xcode gcc-42 add-ons" and choose the appropriate version.
You'll have to get rid of your gfortran 4.6.2 completely or make it inaccessible by changing PATH if possible (which I doubt unless it is in /opt/...).
And do use R CMD SHLIB since that will pass the correct options to compiler and linker.