Trouble installing rJava on Mac ; trouble with JNI

2019-04-07 03:41发布

问题:

RESOLVED!!

See my solution below, in case this question helps others in the future.

Error

As the title described, it it failing for me. The error I'm receiving, when I attempt to install.packages('rJava') from inside R is (with some preceding good checks):

checking whether JNI programs can be compiled... yes
checking JNI data types... configure: error: One or more JNI types differ from the corresponding native type. You may need to use non-standard compiler flags or a different compiler in order to fix this.
ERROR: configuration failed for package ‘rJava’
* removing ‘/usr/local/lib/R/3.2/site-library/rJava’

Fix Attempts

I have checked and tried the following resolutions, none of which worked for me:

  • sudo R CMD javareconf

  • more detailed sudo R CMD javareconf

  • export JAVA_HOME, however in this case, I did not do the LD_LIBRARY_PATH, as it did not seem relevant to a Mac.

No such luck, with any of these attempts.


I had previously had rJava (and RJDBC) installed properly.

[Edit: I later found out, the actual problem was upgrading to OS X 10.11, El Capitan.]


Configuration

$ java -version
java version "1.8.0_45"

> R.Version()
$platform
[1] "x86_64-apple-darwin15.0.0"
$version.string
[1] "R version 3.2.2 (2015-08-14)"

Mac OS itself:

System Version: OS X 10.11.1 (15B42)

回答1:

I did not do the LD_LIBRARY_PATH, as it did not seem relevant to a Mac

Yes, but a Mac has DYLD_LIBRARY_PATH. If you link with -ljvm you have to have the directory containing libjvm.dylib in DYLD_LIBRARY_PATH.

That said, I found it more convenient to link JNI programs with -ljli (in lib/jli), because the programs linked with -ljvm will open a prompt to install Apple's own Java runtime when the system doesn't have it (at least they did on my and our customers' systems some while ago).

Edit: here's a link to the dyld documentation



回答2:

I finally resolved this, via a solution I found here.

The new Mac OS X (10.11, El Capitan) has trouble with env variables.


The newest dev flavor of rJava manages to handle things correctly. Here is what I did to resolve it:

  1. Download version 0.9-8 (rJava_0.9-8.tar.gz) from here
  2. Install it from the downloaded source:

    $ R CMD INSTALL ~/Downloads/rJava_0.9-8.tar.gz

(Or wherever you put it)

That's all it took!