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

Compiling rJava macOS, java8 #153

Open
perpdgo opened this Issue Jun 12, 2018 · 16 comments

Comments

Projects
None yet
8 participants
@perpdgo

perpdgo commented Jun 12, 2018

Dear Simon,

I am having trouble when compiling rJava (0.9-10) from source. I am using macOS highSierra 10.13.5 and JDK 1.8.0_172. I have found that it is related to the issue #151. I have the latest version of R (3.5.0), and I have used "R CMD javareconf" to detect the current java setup and update the configuration in R, every thing seems normal, but when I try to install the package, using "R CMD install rJava", the configuration scripts indicates that "JDK is incomplete".

Below you can see the output from javareconf and the attempt to install the package


$sudo R CMD javareconf
Password:
Java interpreter : /usr/bin/java
Java version : 1.8.0_172
Java home path : /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre
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 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -fPIC -Wall -g -O2 -c conftest.c -o conftest.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre
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.


$R CMD INSTALL rJava
...

=== configuring in jri (/Users/<your_user>/Downloads/rJava/jri)
configure: running /bin/sh ./configure --disable-option-checking '--prefix=/usr/local' --cache-file=/dev/null --srcdir=.
checking build system type... x86_64-apple-darwin17.6.0
checking host system type... x86_64-apple-darwin17.6.0
checking for gcc... clang
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 accepts -g... yes
checking for clang option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -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: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
yes
checking Java version... 1.8.0_172
checking whether /usr/bin/javah actually works... no
checking whether javah was replaced by javac -h... no
configure: error: one or more Java tools are missing.

*** JDK is incomplete! Please make sure you have a complete JDK. JRE is not sufficient.
configure: error: ./configure failed for jri

I have install jdk from oracle and I do not have any other jdk/jre installed.

This message could be related to the code in lines 118-124 and 145 in the file jri/configure.ac,

If I execute in the console:

$/usr/bin/javah -version
javah version "1.8.0_172"

but if I execute
$/usr/bin/javah -version >/dev/null 2>&1
I do not see any output.

Sorry for the long report, I hope it helps.

Regards.

@s-u

This comment has been minimized.

Owner

s-u commented Jun 12, 2018

Thanks. Can you, please, share the content of rJava/jri/config.log?

Also please try if rJava 0.9-9 works for you since that one was using javah unconditionally.

@perpdgo

This comment has been minimized.

perpdgo commented Jun 12, 2018

Dear Simon,

Attached the config.log

config.log

I downloaded rJava 0.9-9 almost at the end of the compilation process it gives an error that indicates that openmp is not supported by the compiler. I am using the last version of Xcode (9.4, 9F1027a), perhaps is a problem with clang, I have compiled rJava 0.9-9 before and it was working.

Below the relevant output generated when trying to compile version 0.9-9

clang -o libjri.jnilib Rengine.o jri.o Rcallbacks.o Rinit.o globals.o rjava.o -dynamiclib -framework JavaVM -fopenmp -L/usr/local/lib -F/Library/Frameworks/R.framework/.. -framework R -lpcre -llzma -lbz2 -lz -licucore -lm -liconv
clang: error: unsupported option '-fopenmp'
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’

Below the output from clang --version

$ clang --version
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Best regards and thanks for the attention.

@pascaloettli

This comment has been minimized.

pascaloettli commented Jun 14, 2018

Hello,
I am facing the same problem with rJava 0.9-10 (macOS 10.13.5, Apple LLVM 9.1.0, jdk-8u172). However, as suggested by Simon, rJava 0.9-9 installed smoothly.

@perpdgo

This comment has been minimized.

perpdgo commented Jun 14, 2018

Thanks pascoloettli,

Probably the problem in my case with rJava 0.9-9 the problem is with the JDK.

Regards.

@s-u

This comment has been minimized.

Owner

s-u commented Jun 14, 2018

@perpdgo your issue with rJava 0.9-9 has nothing to do with rJava - you just don't have the correct compilers to use with R. You have to use the clang compiler from the CRAN pages since Apple's compilers are lacking OpenMP support (see the main CRAN download page).

As for rJava 0.9-10, I'll have to see why javah from Java 1.8 on macOS doesnt' get recognized as working. That older JDK doesn't support the new javac -h option so we have to use javah there.

@perpdgo

This comment has been minimized.

perpdgo commented Jun 15, 2018

Thanks Simon, I will install clang from CRAN and I let you know.

Regards.

@lawremi

This comment has been minimized.

lawremi commented Jun 16, 2018

I can confirm that something is wrong with the javah check with Java 1.8 on the Mac. Interactively, the command returns 0, but somehow the conditional thinks the opposite.

@lawremi

This comment has been minimized.

lawremi commented Jun 16, 2018

Actually, upon further digging, the problem is that /usr/bin/javah is a wrapper that looks under $JAVA_HOME/bin for the actual program. Since R is configured with a JAVA_HOME that ends with jri, it fails to find the real javah, which is actually in $JAVA_HOME/../bin.

@perpdgo

This comment has been minimized.

perpdgo commented Jun 17, 2018

Hi guys,

Can any one of you can share the file in ~/.R/Makevars?

I have installed clang6 from gcc, but still unable to compile r-java 0.9-9,

here the contents of my file

#F77 = /usr/local/bin/gfortran
#FC = $F77
CXX = /usr/local/clang6/bin/clang++ -Wall
LDFLAGS=-L/usr/local/clang6/lib
CC= /usr/local/clang6/bin/clang
SHLIB_CXXLD=ccache /usr/local/clang6/bin/clang++
CXX11 = /usr/local/clang6/bin/clang++
CXX98 = /usr/local/clang6/bin/clang++
CXX14 = /usr/local/clang6/bin/clang++

when I try to install the package I obtain the following:

ld: unexpected token: !tapi-tbd-v3 file '/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd' for architecture x86_64
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)

@perpdgo

This comment has been minimized.

perpdgo commented Jun 17, 2018

Hi have solved the issue, here are the steps that allow me to install successfully r-java 0.9-9 from source

  1. Download and install clang 6 from CRAN
  2. Edit the .bash_profile, and add export PATH=/usr/local/clang6/bin:$PATH
  3. Edit /Library/Frameworks/R.framework/Resources/etc/Makeconf and change the path of the C/C++ compilers,
@AlexSh1mada

This comment has been minimized.

AlexSh1mada commented Jun 20, 2018

Hi @perpdgo @s-u @pascaloettli , I also have this issue, I just can't install rJava and I've been trying to solve it for 2 days now, I've been using r-java 0.9-10, but I can't quite figure out how to install the 0.9-9 version from terminal,
I tried using R --quiet -e 'install.packages("rJava",type="source", repos="https://cran.r-project.org/src/contrib/Archive/rJava/rJava_0.9-9.tar.gz")'
But in return I got that it was not possible to open the URL:

> install.packages("rJava",type="source", repos="https://cran.r-project.org/src/contrib/Archive/rJava/rJava_0.9-9.tar.gz")
 警告:   リポジトリー https://cran.r-project.org/src/contrib/Archive/rJava/rJava_0.9-9.tar.gz/src/contrib に対する索引にアクセスできません :
  no fue posible abrir la URL 'https://cran.r-project.org/src/contrib/Archive/rJava/rJava_0.9-9.tar.gz/src/contrib/PACKAGES'
 警告メッセージ: 
 パッケージ ‘rJava’ が利用できません (for R version 3.5.0)  

Also yeah, my R is in Japanese for some reason and I don't know how to change it to english.

Edit the .bash_profile, and add export PATH=/usr/local/clang6/bin:$PATH
Edit /Library/Frameworks/R.framework/Resources/etc/Makeconf and change the path of the C/C++ compilers

I have to say I'm a beginner so when you say this I'm kind of lost, I'm almost sure I've done some of that while trying to solve this issue with other threads but I'm not 100% sure and I don't want to mess something up, please could you or anyone else reading this tell me what commands I should use?
Thanks for your attention.

@pascaloettli

This comment has been minimized.

pascaloettli commented Jun 20, 2018

@AlexSh1mada It is off topic here, but the correct command is

install.packages("https://cran.r-project.org/src/contrib/Archive/rJava/rJava_0.9-9.tar.gz")
@AlexSh1mada

This comment has been minimized.

AlexSh1mada commented Jun 21, 2018

Thank you @pascaloettli, now I just got a different error, again, no idea why this is happening but I'm trying to fix it, I'll look for what the issue is but if you or anyone else have an idea let me know.

> install.packages("https://cran.r-project.org/src/contrib/Archive/rJava/rJava_0.9-9.tar.gz")
inferring 'repos = NULL' from 'pkgs'
trying URL 'https://cran.r-project.org/src/contrib/Archive/rJava/rJava_0.9-9.tar.gz'
Content type 'application/x-gzip' length 660454 bytes (644 KB)
==================================================
downloaded 644 KB

During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_TIME failed, using "C" 
3: Setting LC_MESSAGES failed, using "C" 
4: Setting LC_MONETARY failed, using "C" 
* installing *source* package 'rJava' ...
** package 'rJava' successfully unpacked and MD5 sums checked
checking for gcc... /usr/local/clang6/bin/clang
checking whether the C compiler works... no
configure: error: in `/private/var/folders/np/kl0b_88d13d86956qsk0w17h0000gn/T/RtmpEDl8wq/R.INSTALL1c962b4f790b/rJava':
configure: error: C compiler cannot create executables
See `config.log' for more details
ERROR: configuration failed for package 'rJava'
* removing '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava'
Warning message:
In install.packages("https://cran.r-project.org/src/contrib/Archive/rJava/rJava_0.9-9.tar.gz") :
  installation of package '/var/folders/np/kl0b_88d13d86956qsk0w17h0000gn/T//Rtmp8VIHws/downloaded_packages/rJava_0.9-9.tar.gz' had non-zero exit status
@hyacz

This comment has been minimized.

hyacz commented Nov 14, 2018

  1. I have encountered the same error. (Mac OS 10.14 / R Open 3.5.1 / Java 1.8.0_191 / rJava 0.9-10 / Clang 6.0.0[CRAN])
...
checking whether /usr/bin/javah actually works... no
checking whether javah was replaced by javac -h... no
configure: error: one or more Java tools are missing.

*** JDK is incomplete! Please make sure you have a complete JDK. JRE is not sufficient.
configure: error: ./configure failed for jri
...
  1. Then I checked my javah, It works as expected by jri/configure

if "$JAVAH" -version >/dev/null 2>&1; then

~
$ /usr/bin/javah -version
javah version "1.8.0_191"
  1. In order to debug I deleted the redirect to dev/null, Now it looks like this:
if "$JAVAH" -version; then

Then reinstall will get this

checking whether /usr/bin/javah actually works... Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre/bin/javah" (-1)
no
checking whether javah was replaced by javac -h... no

As the error message, javah is not in that place, javah is in /usr/bin, I don't know why it can't be found.

~/rJava
$ ll /usr/bin/javah
lrwxr-xr-x  1 root  wheel  75 Sep 26 19:50 /usr/bin/javah -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javah
  1. Finally, I removed this check in jri/configure and rJava was installed correctly.
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (rJava)

@s-u This information helps you check why javah from Java 1.8 on macOS doesnt' get recognized as working ?

@johnstantongeddes

This comment has been minimized.

johnstantongeddes commented Nov 27, 2018

I ran into the same problem and found that on macOS Mojave (and maybe High Sierra?) the Mac OS headers have to be manually installed. Link to my solution on SO with notes on how I solved it.

For completeness here, install the macOS SDK package file using terminal

cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg

After this, in the terminal, configure rJava and install as in the previous answer

sudo R CMD javareconf
R -e "install.packages('rJava')"
@timcharper

This comment has been minimized.

timcharper commented Dec 10, 2018

Running High Sierra here, I got the same error message.

This worked for me:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
    1.8.0_162, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home

$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home

$ export PATH=$JAVA_HOME/bin:$PATH

$ R CMD javareconf

$ R --quiet -e 'install.packages("rJava", type="source", repos="http://cran.us.r-project.org")'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment