Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load rcdk because of rJava #291

Closed
fdq09eca opened this issue Jun 29, 2021 · 8 comments
Closed

Failed to load rcdk because of rJava #291

fdq09eca opened this issue Jun 29, 2021 · 8 comments

Comments

@fdq09eca
Copy link

fdq09eca commented Jun 29, 2021

r$> library(rcdk)                                                                                                       
Loading required package: rcdklibs
Loading required package: rJava
Error: package or namespace load failed forrJava:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(jli, FALSE)
  error: unable to load shared object '/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib':
  dlopen(/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib, 10): no suitable image found.  Did find:
        /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib: mach-o, but wrong architecture
        /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib: mach-o, but wrong architecture
Error: packagerJavacould not be loaded

I came across this similar thread therefore I tried sudo R CMD javareconf but it does not work for me.

chrislam@ChrisLams-MBP MVA_DNF % sudo R CMD javareconf
Password:
Java interpreter : /usr/bin/java
Java version     : 11.0.10
Java home path   : /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar

trying to compile and link a JNI program 
detected JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/include/darwin  -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c conftest.c -o conftest.o
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: ignoring file /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/server/libjvm.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64


JAVA_HOME        : /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.

the following is my Sys.info() and my radian details

r$> Sys.info()                                                                                                                           
                                                                                               sysname 
                                                                                              "Darwin" 
                                                                                               release 
                                                                                              "20.3.0" 
                                                                                               version 
"Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101" 
                                                                                              nodename 
                                                                                  "ChrisLams-MBP.home" 
                                                                                               machine 
                                                                                               "arm64" 
                                                                                                 login 
                                                                                                "root" 
                                                                                                  user 
                                                                                            "chrislam" 
                                                                                        effective_user 
                                                                                            "chrislam"
chrislam@ChrisLams-MBP MVA_DNF % radian
R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Platform: aarch64-apple-darwin20 (64-bit)`
chrislam@ChrisLams-MBP ~ % java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
@randy3k
Copy link
Owner

randy3k commented Jun 29, 2021

Does it work with regular R? It seems to be a problem of your JAVA installation.

@fdq09eca
Copy link
Author

Does it work with regular R? It seems to be a problem of your JAVA installation.

it does not either..

chrislam@ChrisLams-MBP ~ % R

R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages("rJava")
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cran.ma.imperial.ac.uk/bin/macosx/big-sur-arm64/contrib/4.1/rJava_1.0-4.tgz'
Content type 'application/x-gzip' length 782994 bytes (764 KB)
==================================================
downloaded 764 KB


The downloaded binary packages are in
	/var/folders/t6/qy2rcbdx0g9_fv98q1g48v_h0000gn/T//RtmpmUBuDD/downloaded_packages
> lib
libcurlVersion       library.dynam       
library              library.dynam.unload
> library(rJava)
Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(jli, FALSE)
  error: unable to load shared object '/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib':
  dlopen(/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib, 10): no suitable image found.  Did find:
	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib: mach-o, but wrong architecture
	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib: mach-o, but wrong architecture
> 

@randy3k
Copy link
Owner

randy3k commented Jun 29, 2021

Close it now as it is not a radian issue.

@randy3k randy3k closed this as completed Jun 29, 2021
@randy3k
Copy link
Owner

randy3k commented Jun 29, 2021

I am sorry that I don't have many experiences with rJava. But I guess you just need to install a native version of Java virtual machine.

@psobolewskiPhD
Copy link

Yeah this line in the error
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/jli/libjli.dylib: mach-o, but wrong architecture
Means you have mixed architectures.
On Apple Silicon all components need to be either x86, so the whole kit and caboodle is emulated via Rosetta or all arm64 so everything is native.
Looks like your R is native (arm64), meanwhile AdoptOpenJDK does not yet have a native JDK/JRE. You can install a native one from homebrew:
https://formulae.brew.sh/formula/openjdk#default
Or from Azul:
https://www.azul.com/downloads/?os=macos&architecture=arm-64-bit
You may need to install the package from source, but I think most if not all CRAN packages are now arm64 aware.

If you need to use Adopt specifically, download x86 R and use that with your AdoptOpenJDK (with a speed penalty).

@fdq09eca
Copy link
Author

fdq09eca commented Jun 30, 2021

Thanks @psobolewskiPhD, I have successfully loaded rJava by installing from Azul and setting JAVA_HOME to the respective path but the rcdk problem still persists..

> library("rJava")
> library("rcdk")
Loading required package: rcdklibs
zsh: trace trap  R

@psobolewskiPhD
Copy link

psobolewskiPhD commented Jun 30, 2021

Hmm.
Have you tried deleting the packages and installing again after the Java JDK fix?
rcdk does show as arm64 on CRAN...
But is that just a wrapper so maybe CDK has some compiled code?
At the same time, I'd sort of expect that mach-o architecture error, Trace trap suggests some sort of bug or NSException I think?

Edit:
Wait, it might be arch after all. See:
https://cran.r-project.org/web/checks/check_results_rcdk.html
rcdk on arm64 is failing:
https://www.r-project.org/nosvn/R.check/r-release-macos-arm64/rcdk-00check.html
Not sure why CRAN is hosting a failing binary.
If you have xcode-commandline tools you can try to install it from source:
install.packages("rcdk", type = "source")
Or even see if there is something newer on their GitHub:
https://github.com/CDK-R/cdkr

@fdq09eca
Copy link
Author

> install.packages(rcdk, type"source")
Error: unexpected string constant in "install.packages(rcdk, type"source""
> install.packages(rcdk, type="source")
Error in install.packages(rcdk, type = "source") : 
  object 'rcdk' not found
> install.package(rcdk, type="source")
Error in install.package(rcdk, type = "source") : 
  could not find function "install.package"
> install.packages("rcdk", type="source")
trying URL 'https://cran.ma.imperial.ac.uk/src/contrib/rcdk_3.5.0.tar.gz'
Content type 'application/x-gzip' length 270214 bytes (263 KB)
==================================================
downloaded 263 KB

* installing *source* packagercdk...
** packagercdksuccessfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
sh: line 1: 42816 Trace/BPT trap: 5       R_TESTS= '/Library/Frameworks/R.framework/Resources/bin/R' --no-save --no-restore --no-echo 2>&1 < '/var/folders/t6/qy2rcbdx0g9_fv98q1g48v_h0000gn/T//RtmpxRdKiW/filea73973abd4a4'
ERROR: lazy loading failed for packagercdk* removing/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rcdkThe downloaded source packages are in/private/var/folders/t6/qy2rcbdx0g9_fv98q1g48v_h0000gn/T/RtmpRx3rbx/downloaded_packagesWarning message:
In install.packages("rcdk", type = "source") :
  installation of packagercdkhad non-zero exit status

seems it does not work, I tried their to install by devtools as suggested by CDK-R repo

library(devtools)
install_github("https://github.com/CDK-R/rcdklibs")
install_github("https://github.com/CDK-R/cdkr", subdir="rcdk")

but still not success. I think the most problematic is the dependence rcdklibs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants