s-u / rJava

R to Java interface
https://RForge.net/rJava
235 stars 77 forks source link

Compile error #288

Closed arecibo closed 2 years ago

arecibo commented 2 years ago

I am using R 4.2 (unstable 2021-11-21 r81221) on M1 Silicon Mac.

sudo R CMD javareconfshowed the following message.

Java interpreter : /usr/bin/java
Java version     : 17.0.1
Java home path   : /Library/Java/JavaVirtualMachines/jdk-17.0.1.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/jdk-17.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk-17.0.1.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/jdk-17.0.1.jdk/Contents/Home/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk-17.0.1.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.

When I tried to compile rJava, I got the following message.

> install.packages("rJava", type = "source")
Installing package into '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library'
(as 'lib' is unspecified)
Warning in install.packages("rJava", type = "source") :
  'lib = "/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) yes
trying URL 'https://cran.biodisk.org/src/contrib/rJava_1.0-5.tar.gz'
Content type 'application/x-gzip' length 1042083 bytes (1017 KB)
==================================================
downloaded 1017 KB

[1] "ko_KR.UTF-8/ko_KR.UTF-8/ko_KR.UTF-8/C/ko_KR.UTF-8/ko_KR.UTF-8"
[1] "en_US.UTF-8"
* installing *source* package 'rJava' ...
** package 'rJava' successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... clang -arch arm64
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 clang -arch arm64 accepts -g... yes
checking for clang -arch arm64 option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -arch arm64 -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... rm: cannot remove 'conftest.dSYM': Is a directory
rm: cannot remove 'conftest.dSYM': Is a directory
yes
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 clang -arch arm64 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 : '/usr/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : '-I/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/include/darwin'
java libs   : '-L/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/lib/server -ljvm'
checking whether Java run-time works... yes
checking whether -Xrs is supported... yes
checking whether -Xrs will be used... yes
checking whether JVM will be loaded dynamically... yes
checking whether JNI programs can be compiled... yes
checking whether JNI programs run... yes
checking JNI data types... ok
checking whether JRI should be compiled (autodetect)... yes
checking whether debugging output should be enabled... no
checking whether memory profiling is desired... no
checking whether threads support is requested... no
checking whether callbacks support is requested... no
checking whether JNI cache support is requested... no
checking whether headless init is enabled... yes
checking whether JRI is requested... yes
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating R/zzz.R
config.status: creating src/config.h
=== configuring in jri (/private/var/folders/jt/srf62br55mg1pxqkhbf0ghjh0000gn/T/Rtmpaj7k31/R.INSTALL233065c6423e/rJava/jri)
configure: running /bin/sh ./configure --disable-option-checking '--prefix=/usr/local'  'LDFLAGS=-L/opt/homebrew/opt/jpeg-turbo/lib' 'CPPFLAGS=-I/opt/homebrew/include' --cache-file=/dev/null --srcdir=.
checking build system type... Invalid configuration `arm64-apple-darwin21.1.0': machine `arm64-apple' not recognized
configure: error: /bin/sh tools/config.sub arm64-apple-darwin21.1.0 failed
configure: error: ./configure failed for jri
ERROR: configuration failed for package 'rJava'
* removing '/Users/arecibo/.Rpackages/rJava'

The downloaded source packages are in
    '/private/var/folders/jt/srf62br55mg1pxqkhbf0ghjh0000gn/T/Rtmp6X2a49/downloaded_packages'
Warning message:
In install.packages("rJava", type = "source") :
  installation of package 'rJava' had non-zero exit status
>

How to solve this problem?

s-u commented 2 years ago

There are several options:

  1. use binary from CRAN, it works (i.e. do NOT set type="source")

  2. If you compile from sources disable JRI via --disable-jri, i.e., install.packages("rJava", configure.args="--disable-jri")

  3. if you compile for sources and still need JRI, try the latest dev version, i.e., install.packages("rJava", repo="https://rforge.net")

The underlying issue is that your system doesn't get recognized correctly when configuring JRI. I cannot reproduce it so I don't know why, but the dev version uses latest automake tools so hopefully those should work. The correct build name for M1 macOS is aarch64-apple-darwin2*.

arecibo commented 2 years ago

Many thanks. The second option worked!