在Mac OS上使用brew安装RDFLAGS上的Fortran库路径失败

时间:2018-10-24 22:13:17

标签: java r macos gfortran

我正在尝试在rJava上的R上安装Mac High Sierra 10.13.6软件包。

install.packages("rJava")

工作正常,但是当我尝试加载软件包时,我得到了:

Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib/server/libjvm.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
  Reason: no suitable image found.  Did find:
    /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/libjvm.dylib: mach-o, but wrong architecture
    /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/libclient.dylib: mach-o, but wrong architecture

我尝试通过以下方法来关注this

install.packages('rJava', repos = 'http://rforge.net')

但是收到此错误消息:

configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.

If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.

ERROR: configuration failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

因此尝试运行:

sudo R CMD javareconf

但是我得到了:

detected JNI linker flags : -L/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries -ljvm
/usr/local/clang4/bin/clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^~~~~~~
1 error generated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program

因此尝试使用以下方法将Rjava重新安装:

brew reinstall R --with-openblas --with-java

但是我收到此错误消息:

checking whether mixed C/Fortran code can be run... configure: WARNING: cannot run mixed C/Fortran code
configure: error: Maybe check LDFLAGS for paths to Fortran libraries?

我的gfortran是从here abd下载的,位于:

/usr/local/gfortran

所以我设置:

export LDFLAGS="-L/usr/local/gfortran/lib -lgfortran"

$ echo $LDFLAGS
-L/usr/local/gfortran/lib -lgfortran

$ ls /usr/local/gfortran/lib
gcc         libatomic.la        libgcc_ext.10.4.dylib   libgfortran.spec    libitm.la       libquadmath.la      libstdc++.a     libubsan.dylib
i386            libcc1.0.so     libgcc_ext.10.5.dylib   libgomp.1.dylib     libitm.spec     libsanitizer.spec   libstdc++.a-gdb.py  libubsan.la
libasan.3.dylib     libcc1.la       libgcc_s.1.dylib    libgomp.a       libobjc-gnu.4.dylib libssp.0.dylib      libstdc++.dylib
libasan.dylib       libcc1.so       libgcc_s_ppc64.1.dylib  libgomp.dylib       libobjc-gnu.a       libssp.a        libstdc++.la
libasan.la      libcilkrts.5.dylib  libgcc_s_x86_64.1.dylib libgomp.la      libobjc-gnu.dylib   libssp.dylib        libstdc++fs.a
libasan_preinit.o   libcilkrts.a        libgfortran.3.dylib libgomp.spec        libobjc-gnu.la      libssp.la       libstdc++fs.la
libatomic.1.dylib   libcilkrts.dylib    libgfortran.a       libitm.1.dylib      libquadmath.0.dylib libssp_nonshared.a  libsupc++.a
libatomic.a     libcilkrts.la       libgfortran.dylib   libitm.a        libquadmath.a       libssp_nonshared.la libsupc++.la
libatomic.dylib     libcilkrts.spec     libgfortran.la      libitm.dylib        libquadmath.dylib   libstdc++.6.dylib   libubsan.0.dylib

我重新跑了:

R --with-openblas --with-java

但是它会产生相同的错误。

我看到的是它一直在打印:

checking for Fortran 77 libraries of gfortran...  -L/usr/local/opt/openblas/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0 -L/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/../../.. -lgfortran -lquadmath -lm

其中不包括我添加到LDFLAGS的路径。

所以我的问题是:

  1. 如何让rJavaR上工作?
  2. 如果要达到1需要完成我上面描述的过程,那么我该如何完成?可能从如何使R --with-openblas --with-java成功完成开始。

0 个答案:

没有答案