error while loading shared libraries: libjvm.so: - java-native-interface

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.

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 :
Create the java and the cc files (cf. link above) in the same repertory.
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 }
Go the repertory and compile the java class :
$ javac Main.java.
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
)
Export the lib path
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIBPATH}
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
Should be good :)
./a.out
Hello, world!
Hello, Java!

Related

error while loading shared libraries: libboost_serialization.so.1.66.0: cannot open shared object file: No such file or directory [duplicate]

There is a laptop on which I have no root privilege.
onto the machine I have a library installed using configure --prefix=$HOME/.usr .
after that, I got these files in ~/.usr/lib :
libXX.so.16.0.0
libXX.so.16
libXX.so
libXX.la
libXX.a
when I compile a program that invokes one of function provided by the library with this command :
gcc XXX.c -o xxx.out -L$HOME/.usr/lib -lXX
xxx.out was generated without warning, but when I run it error like this was thrown:
./xxx.out: error while loading shared libraries: libXX.so.16: cannot open shared object file: No such file or directory , though libXX.so.16 resides there.
my clue-less assumption is that ~/.usr/lib wasn't searched when xxx.out is invoked.
but what can I do to specify path of .so , in order that xxx.out can look there for .so file?
An addition is when I feed -static to gcc, another error happens like this:
undefined reference to `function_proviced_by_the_very_librar'
It seems .so does not matter even though -L and -l are given to gcc.
what should I do to build a usable exe with that library?
For other people who has the same question as I did
I found a useful article at tldp about this.
It introduces static/shared/dynamic loaded library, as well as some example code to use them.
There are two ways to achieve that:
Use -rpath linker option:
gcc XXX.c -o xxx.out -L$HOME/.usr/lib -lXX -Wl,-rpath=/home/user/.usr/lib
Use LD_LIBRARY_PATH environment variable - put this line in your ~/.bashrc file:
export LD_LIBRARY_PATH=/home/user/.usr/lib
This will work even for a pre-generated binaries, so you can for example download some packages from the debian.org, unpack the binaries and shared libraries into your home directory, and launch them without recompiling.
For a quick test, you can also do (in bash at least):
LD_LIBRARY_PATH=/home/user/.usr/lib ./xxx.out
which has the advantage of not changing your library path for everything else.
Should it be LIBRARY_PATH instead of LD_LIBRARY_PATH.
gcc checks for LIBRARY_PATH which can be seen with -v option

Cygwin won't compile any c++ files

When I try to compile my Fibonacci.cpp file I get this from the compiler:
$ g++ Fibonacci.cpp
C:/cygwin/lib/gcc/i686-pc-cygwin/4.9.3/cc1plus.exe: error while loading shared libraries: cygcloog-isl-4.dll: cannot open shared object file: No such file or directory
I've downloaded the gcc-g++: GNU Compiler Collection (C++) library and it's not working. Am I missing another library?
You need to install the libcloog-isl4 package when you run the setup.exe. You are missing that file in your C:/cygwin64/bin directory. I had the same problem and I was also missing cygisl-10.dll and I had to install libisl10 package.
See this cannot compile anything with gcc on cygwin32; missing cygisl-10.dll.
Unfortunately I'm getting a different error now that I solved that, so I'm not guaranteeing a fix.

how to compile with liblbfgs?

I downloaded liblbfgs from here and compiled the sample code from its document with
g++ sample.cpp -o sample -llbfgs
Then I run
./sample
But it says
./sample: error while loading shared libraries:
liblbfgs-1.10.so: cannot open shared object file: No such file or directory
Are there any extra flags that I have to add? Thanks!!
Solution for similar problem is discussed here. You may have to do ldconfig, as you have recently installed a shared library.

Program can't find libboost_program_options.so.1.47.0 at runtime

Since I don't have root permission to install Boost C++ library, I installed it under my home local. When compiling, I used:
g++ -I/home/name/local/boost_1_47_0 -L/home/name/local/boost_1_47_0/stage/lib foo.cc -o foo -lboost_program_options
but at runtime, it goes:
error while loading shared libraries: libboost_program_options.so.1.47.0: cannot open shared object file: No such file or directory
and ldd gives:
libboost_program_options.so.1.47.0 => not found
I also tried to specify the absolute path of the library, but it doesn't work either:
g++ /home/name/local/boost_1_47_0/stage/lib/libboost_program_options.so.1.47.0 -I/home/name/local/boost_1_47_0 -L/home/name/local/boost_1_47_0/stage/lib foo.cc -o foo
Try using the LD_LIBRARY_PATH environment variable to instruct the run-time linker where to find the library:
export LD_LIBRARY_PATH=/home/name/local/boost_1_47_0/stage/lib
Then rerun your application.
I'm a newbie, so don't take my words too seriously. Furthermore, this question is several months old and I guess solved long ago. Nevertheless, here's what I think.
You specify the library path to the linker, so the program compiles and links fine. However, when you try to execute the binary, it looks for the libs in the environment defined path.
I guess this can be fixed by typing into bash
export PATH=$PATH:path_to_your_library_folder
Best Regards
Miroslav

How do I link against libtool static la library?

I have compiled this library successfully. It generates a libcds2.la file that I am trying to link into my own project. I have all files (including the .h file) in the same directory as my project file. When I try to link and use the functions of said library, using:
g++ -o test -I/opt/include/ -L/opt/lib/ -lcds2 libcdsNoptrs.cpp util.cpp
comes back with
./test: error while loading shared libraries: libcds2.so.2:
cannot open shared object file: No such file or directory
whatever that is. But the point is that most of the time it just doesn't recognize the library. I assume I'm doing something wrong with the file paths, but can't figure it out. My test file is a C++ file including #include "libcds2/array.h" and everything is installed in opt/lib, opt/include, ugly, I know, but that's what the Makefile generated.
Any pointers?
The libtool .la is a 'meta data' file. After building the cds2 library, it's expected that libtool will also be used in 'link' mode to build any of the package's tests, etc.
Typically, the in the directory you find the .la file, you will find the .a and .so under the .libs subdirectory. The .libs/libcds2.a file will be found there, provided configure was given the --enable-static option (or it is enabled by default). But, my understanding is that you've installed the package in /opt :
g++ -I/opt/include/ libcdsNoptrs.cpp util.cpp -o test /opt/lib/libcds2.a
Otherwise, if libcds2 isn't installed, just supply a path to: .../libcds2/lib/.libs/libcds2.a
Unless you want to use libtool in --link mode with -static to handle everything. But learning the advantages of libtool is usually an exercise for a rainy day:)