Why R is unable to load a shared object?

I am trying to use XLConnect library in R. If I execute

library(XLConnect)

I get the following error message:

JAVA_HOME cannot be determined from the Registry

To resolve this problem I set first the JAVA_HOME variable:

Sys.setenv(JAVA_HOME='C:/Program Files (x86)/Java/jre1.8.0_65')
library(XLConnect)

It looks like it helps me to come further but then I get another problem:

unable to load shared object 'C:/Program Files/R/R-3.2.2/library/rJava/libs/x64/rJava.dll'

It wonder why R cannot load rJava.dll . At least this file is located in the folder where R searches for it:

C:Program FilesRR-3.2.2libraryrJavalibsx64

ADDED

Please note that the rJava.dll file exists and it is located there, where R is searching for it. I guess that the problem is in incompatibility between 32bit and 64bit versions. I assume that because R complains:

% 1 is not a valid Win32 application

Well, why do R expect it to be a Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder with Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder with x64` in the name (so, I assume it is also a 64bit version).


I faced the same issue . Please locate jvm.dll should be in (your JRE version could be different )

C:Program Files (x86)Javajre1.8.0_65binclient

or

C:Program Files (x86)Javajre1.8.0_65binserver

add this path to your windows system path and you are good to go .but keep in mind the version of jre and R should be consistent,if your java is in Program Files its 64 bit so launch from 64 bit R if its in Program Files (x86) its 32 bit so use 32 bit R

like in my case it showed error in 64 bit 在这里输入图像描述

but worked perfectly in 32 bit 在这里输入图像描述


You did use / instead of .

Sys.setenv(JAVA_HOME='C:Program Files (x86)Javajre1.8.0_65') 
library(XLConnect)

I am using UNIX. Therefore I cannot test it by myself but your path might be wrong as well.

According to this post you can search it by using this:

find.java <- function() {
    for (root in c("HLM", "HCU")) for (key in c("SoftwareJavaSoftJava Runtime Environment", 
        "SoftwareJavaSoftJava Development Kit")) {
        hive <- try(utils::readRegistry(key, root, 2), 
          silent = TRUE)
        if (!inherits(hive, "try-error")) 
          return(hive)
    }
    hive
}

credit goes to @nograpes for the function and this article for helping me giving you the answer.

链接地址: http://www.djcxy.com/p/88808.html

上一篇: 用C ++解开嵌套元组

下一篇: 为什么R无法加载共享对象?