jni failed with no `jvm` command
sigrlami opened this issue · 5 comments
I'm using Fedora Linux, openjdk
and openjdk-devel
are installed in the system, but none of them export command jvm
. When I'm building java-inline
and in particular jni
library I get the following error
-- While building package jni-0.2.3 using:
/home/sigrlami/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0 configure --with-ghc=/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/bin/ghc --with-ghc-pkg=/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/bin/ghc-pkg --user --package-db=clear --package-db=global --package-db=/home/sigrlami/.stack/snapshots/x86_64-linux/lts-8.22/8.0.2/pkgdb --package-db=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/pkgdb --libdir=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/lib --bindir=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/bin --datadir=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/share --libexecdir=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/libexec --sysconfdir=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/etc --docdir=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/doc/jni-0.2.3 --htmldir=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/doc/jni-0.2.3 --haddockdir=/home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/install/x86_64-linux/lts-8.22/8.0.2/doc/jni-0.2.3 --dependency=base=base-4.9.1.0 --dependency=bytestring=bytestring-0.10.8.1 --dependency=containers=containers-0.5.7.1 --dependency=inline-c=inline-c-0.5.6.1-2pSLvIEC8gg9yL15JFH39 --dependency=singletons=singletons-2.2-AjIoW7ouIQy1XUxXDvyPLZ --dependency=thread-local-storage=thread-local-storage-0.1.1-FpcC9hY7QTfBqXOxscYOUn
Process exited with code: ExitFailure 1
Logs have been written to: /home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/logs/jni-0.2.3.log
Configuring jni-0.2.3...
Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2: Missing dependency on a foreign
library:
* Missing C library: jvm
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
I can create an environment variable, but need to point jvm
to somewhere. Can you tell where jvm
variable should point in OpenJDK?
I looked up the source code and found a relevant path for it, but in Fedora you have only libjvm.so
in /etc/alternatives/java_sdk_1.8.0/jre/lib/amd64/server/
. I tried to make alias, and symlink in etc/alternatives/java_sdk_1.8.0/lib/openjdk/jre/lib/amd64/server/
but without success
@sigrlami I think you need to supply --extra-lib-dirs
and --extra-include-dirs
to stack that point to the relevant directories of your openjdk install, unless you're using use stack --nix build
. IIRC, you might also need to set LD_LIBRARY_PATH
to point to .../jre/lib/amd64/server/
as well. At least, that's what the shell.nix
of this repository does, so it's probably necessary at some point.
@alpmestan Indeed, I needed LD_LIBRARY_PATH
but running
stack build --extra-lib-dirs='/etc/alternatives/java_sdk/jre/lib/amd64/server' --extra-include-dirs="/etc/alternatives/java_sdk/jre/lib/amd64/server"
gives following error
jni-0.2.3: configure
jni-0.2.3: build
-- While building package jni-0.2.3 using:
/home/sigrlami/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /home/sigrlami/work/projects-hs/tenderoom/tenders/api/.stack-work/logs/jni-0.2.3.log
Configuring jni-0.2.3...
Building jni-0.2.3...
Preprocessing library jni-0.2.3...
NativeMethod.hsc:13:17: fatal error: jni.h: No such file or directory
compilation terminated.
compiling .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Foreign/JNI/NativeMethod_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Foreign/JNI/NativeMethod_hsc_make.c -o .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Foreign/JNI/NativeMethod_hsc_make.o -fno-stack-protector -fno-stack-protector -D__GLASGOW_HASKELL__=800 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -I/etc/alternatives/java_sdk/jre/lib/amd64/server -std=c11 -I.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/autogen -include .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/autogen/cabal_macros.h -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/home/sigrlami/.stack/snapshots/x86_64-linux/lts-8.21/8.0.2/lib/x86_64-linux-ghc-8.0.2/vector-0.11.0.0-CSVBj3oTK2iCG5BGLIuhef/include -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/directory-1.3.0.0/include -I/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/unix-2.7.2.1/include -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/etc/alternatives/java_sdk/jre/lib/amd64/server -I/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/bytestring-0.10.8.1/include -I/home/sigrlami/.stack/snapshots/x86_64-linux/lts-8.0/8.0.2/lib/x86_64-linux-ghc-8.0.2/primitive-0.6.1.0-6AbSTw9JXz141LE5p6LGH/include -I/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/time-1.6.0.1/include -I/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/base-4.9.1.0/include -I/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1/include -I/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/include -I/home/sigrlami/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/include/
is that mean I still use wrong directory? it picked jvm
tho
Probably, I need to point to include
somehow
Yes, you need to specify whatever directory the JNI headers live in as --extra-include-dirs
, it's not deduced from the lib dir. No need however I think to specify the directory with libjvm.so as an extra include dir, there probably isn't any header in there. Just specify the directory with the headers as --extra-include-dirs
and you should be fine.
Adding to stack.yaml
extra-include-dirs:
- /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-1.b12.fc25.x86_64/include # jni.h
- /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-1.b12.fc25.x86_64/include/linux # jni_md.h
extra-lib-dirs:
- /etc/alternatives/java_sdk/jre/lib/amd64/server
fixes it, even without LD_LIBRARY_PATH
. The only inconvinience here is to point to right version after java updates. @alpmestan thanks for hints!