安装Java时找不到文件jni.h

时间:2019-09-25 19:06:52

标签: java r rjava

我正在尝试在rJava上安装R。我运行以下

install.packages("rJava", type = 'source')

具有以下输出:

trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-11.tar.gz'
Content type 'application/x-gzip' length 675188 bytes (659 KB)
==================================================
downloaded 659 KB

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... /usr/local/Cellar/gcc/9.2.0/bin/gcc-9
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /usr/local/Cellar/gcc/9.2.0/bin/gcc-9 accepts -g... yes
checking for /usr/local/Cellar/gcc/9.2.0/bin/gcc-9 option to accept ISO C89... none needed
checking how to run the C preprocessor... /usr/local/Cellar/gcc/9.2.0/bin/gcc-9 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... no
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether /usr/local/Cellar/gcc/9.2.0/bin/gcc-9 supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/Users/112186/.jenv/shims/java'
archiver    : '/Users/112186/.jenv/shims/jar'
compiler    : '/Users/112186/.jenv/shims/javac'
header prep.: '/Users/112186/.jenv/shims/javah'
cpp flags   : ''
java libs   : ''
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.6/Resources/library/rJava’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava’
Warning in install.packages :
  installation of package ‘rJava’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/7_/n_pmyvxs5b56zdy5qh4gfmt8x_n_tl/T/Rtmp5snSGe/downloaded_packages’

因此,我从https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads-5672538.html下载了最后一个Java SE。在终端上,运行以下命令:R CMD javareconf(与命令R CMD javareconf -e类似的输出):

Java interpreter : /Users/112186/.jenv/shims/java
Java version     : 1.6.0_65
Java home path   : /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Java compiler    : /Users/112186/.jenv/shims/javac
Java headers gen.: /Users/112186/.jenv/shims/javah
Java archive tool: /Users/112186/.jenv/shims/jar

trying to compile and link a JNI program 
detected JNI cpp flags    : 
detected JNI linker flags : -L/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries -ljvm
/usr/local/Cellar/gcc/9.2.0/bin/gcc-9 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -Wall -g -O2  -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: jni.h: No such file or directory
    1 | #include <jni.h>
      |          ^~~~~~~
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program


JAVA_HOME        : /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Java library path: 
JNI cpp flags    : 
JNI linker flags : 
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.

问题似乎是sw无法找到jni.h文件。但是,我可以在Mac中找到2个这样的文件:

/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk 1/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h

哪个是正确的文件?我怎样才能让sw找到这些文件?

在这里您可以找到有关我的Java的一些信息:

PST9972:tmp 112186$ javac -version
javac 1.6.0_65
PST9972:tmp 112186$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-468)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode)
PST9972:tmp 112186$ which javac
/Users/112186/.jenv/shims/javac
PST9972:tmp 112186$ which java
/Users/112186/.jenv/shims/java
PST9972:tmp 112186$ 

我在这个线程R CMD javareconf not finding jni.h上遵循了一些答案。但是命令apt updateapt: invalid flag: update )给我错误。另外@KevinZarca(R: rJava package install failing)的建议对我不起作用,因为第一步是

sudo update-alternatives --config java. 
Password:
sudo: update-alternatives: command not found

给我错误。 谢谢您的帮助。

0 个答案:

没有答案