Jean
Jean

Reputation: 1857

error while loading shared libraries: libjvm.so:

I am trying to make this JNI example works. I am able to compile all the files but I can not launch the executable because of this error :

./TEST: error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory

I have checked all the paths, the compilation goes without errors...
Now I think that is linked with my operating system (OpenSuse) or my java version : I am running java 1.7 and the code use the JVM 1.6 (vm_args.version = JNI_VERSION_1_6;).. and JNI_VERSION_1_7 does not seem to exist.

Upvotes: 5

Views: 12207

Answers (1)

Jean
Jean

Reputation: 1857

I found a very good example, one of the best on the web I guess, because the author wrote down the paths of each file he uses : Tutorial

I still had a library problem so here is how I managed to get all working :

  1. Create the java and the cc files (cf. link above) in the same repertory.
  2. Edit the following line in main.cc with the path of your Java class :

{ const_cast<char*>("-Djava.class.path=PATH_TO_JAVA_CLASS"), NULL }

  1. Go the repertory and compile the java class :

$ javac Main.java.

  1. Look for the file libjvm.so on your computer. Once you have found it, edit the lib path as follows :

$ LIBPATH=PATH_TO_LIBJVM.SO

(for me it was in /usr/lib/jvm/java-1.7.0-openjdk-1.7.0/jre/lib/amd64/server )

  1. Export the lib path

$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIBPATH}

  1. Now you just have to compile the main.cc file. I had a problem because jni.h was not found:

    a. Find jni.h (for me /usr/lib/jvm/java-1.7.0-openjdk-1.7.0/include/)

    b. If you have a problem with jni_md.h, create a symbolic link of jni_md.h in the same folder of jni.h

    c. Compile as follows :

$ g++ -Wall main.cc -I/PATH_TO_jni.h -L${LIBPATH} -ljvm

  1. Should be good :)

./a.out

Hello, world!

Hello, Java!

Upvotes: 4

Related Questions