Question

I hope that somebody can help me with my problem. I am compiling on Linux some C wrapper for JNI that was originally created for Windows (I had a question that was already solved [here][1]). My current problem is the following.

The code basically consists in aaa.c, aaa.h, bbb.c and bbb.h

aaa.h is the header generated by "javah" tool.

aaa.c is the implementation of aaa.h bbb.h and bbb.c have some

functions called by aaa.c, one of them is:

int jstring2char(JNIEnv*, jstring, char**);

Now, I created a project in Code::Blocks. When the project is built these are the commands executed:

gcc -Wall  -g -D_GNU_SOURCE -DUNIX    -I../somepath/Inc -I/usr/local/jdk1.7.0_40/include/linux -I/usr/local/jdk1.7.0_40/include  -c /somepath/Scr/aaa.c -o obj/Debug/aaa.o
gcc -Wall  -g -D_GNU_SOURCE -DUNIX    -I../somepath/Inc -I/usr/local/jdk1.7.0_40/include/linux -I/usr/local/jdk1.7.0_40/include  -c /somepath/Scr/bbb.c -o obj/Debug/bbb.o
g++ -shared  obj/Debug/aaa.o obj/Debug/bbb.o   -o bin/Debug/libWrapper.so  

The process is completed with 0 errors, 0 warnings.

Then I installed the library in /opt/somepath:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/somepath

Now when I try to load the generated library

System.loadLibrary("libWrapper.so");

The error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no libWrapper.so in java.library.path

is generated. My first guess is that there is some unsatisfaied dependency so I rn ldd:

root@Ubuntu10:/opt/somepath# ldd libWrapper.so
    linux-gate.so.1 =>  (0x00110000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00161000)
    libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x00111000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00662000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00bae000)
    /lib/ld-linux.so.2 (0x00915000)

So my first problems is that I don't know if "linux-gate.so.1" is what is causing the problem.

In the other hand, I tested by loading the library with the jna API, just to check if there was a more specific error message:

Native.loadLibrary("libWrapper.so", SClass.class);

In effect, I got at different message:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libWrapper.so': libWrapper.so: undefined symbol: jstring2char

jstring2char is a function declared in bbb.h, implemented in bbb.c, wich is called by aaa.c. Now it seems that aaa.c is not resolving the bbb.c functions, despite both were linked at build time.

Now my questions is what could be the cause of the UnsatisfiedLinkError, linux-gate.so.1 or the function jstring2char?. What hints could the community give me?.

Thank you very much. [1]:

Was it helpful?

Solution

You need to say:

System.loadLibrary("Wrapper");

The file name is computed automatically depending on your system (e.g. it'd be Wrapper.dll on Windows).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top