开发者

java.lang.UnsatisfiedLinkError - loading multiple lib files?

At first, this error looked normal to me, but after trying all known things, I still have no luck running my program. So please let me explain in detail.

I am trying to run TC(TokyoCabinet) example using TC's java api on Ubuntu. Both TC and Tc-java got built properly and installed in my home directory. (Not /usr/local/lib).

I am running the program like -

$ java -Djava.library.path=/home/siddharth/tools/tc-java/lib -classpath ./bin/:lib/tokyocabinet.jar HdbTest

And getting following error -

Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/siddharth/tools/tc-java/lib/libjtokyocabinet.so.1.1.0: /home/siddharth/tools/tc-java/lib/libjtokyocabinet.so.1.1.0: undefined symbol: tcversion
 at java.lang.ClassLoader$NativeLibrary.load(Native Method)
 at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
 at java.lang.Runtime.loadLibrary0(Runtime.java:822)
 at java.lang.System.loadLibrary(System.java:993)
 at tokyocabinet.Loader.load(Loader.java:41)
 at tokyocabinet.HDB.<clinit>(HDB.java:37)
 at HdbTest.main(HdbTest.java:10)

Now, this error is about symbol "tcversion". So I ran -

$ nm /home/siddharth/tools/tc-java/lib/libjtokyocabinet.so.1.1.0  | 开发者_运维问答grep -i tcversion
         U tcversion

which means tcversion is not there.

Actually tcversion is inside main TC library

$ nm /home/siddharth/tools/tc/lib/libtokyocabinet.so | grep -i tcversion
0008096c D tcversion

Now, the question is, how can I make these libraries connect?


Better solution is to change Makefile before running 'make' and 'make install'.

Inside Makefile replace LIBS by

LIBS = -lbz2 -lz -lpthread -lm -lc /home/siddharth/tools/tc/lib/libtokyocabinet.so.9

Add tc's lib dir in a new tc.conf file under ld.so.conf.d

$ cat /etc/ld.so.conf.d/tc.conf 
/home/siddharth/tools/tc/lib

Run ldconfig

sudo ldconfig -v

Build tc-java make INCLUDEDIR="/home/siddharth/tools/tc/include" LIBDIR="/home/siddharth/tools/tc/lib"

Check if its linked properly

$ ldd libjtokyocabinet.so
        linux-gate.so.1 =>  (0xb7fd7000)
        libbz2.so.1.0 => /lib/libbz2.so.1.0 (0xb7fa0000)
        libz.so.1 => /usr/lib/libz.so.1 (0xb7f8b000)
        libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7f72000)
        libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7f4d000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7dfe000)
        libtokyocabinet.so.9 => /home/siddharth/tools/tc/lib/libtokyocabinet.so.9 (0xb7d82000)
        /lib/ld-linux.so.2 (0xb7fd8000)
        librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7d79000)

Run TC's checks

make check

Now install library

make install


I think I have solved it. It was an issue while building native java library.

I tried rebuilt it using

make LDFLAGS="-L/home/siddharth/tools/tc/lib" LIBS="/home/siddharth/tools/tc/lib/libtokyocabinet.so.9.9.0" INCLUDEDIR="/home/siddharth/tools/tc/include"

Now ldd shows proper links to TC libs

$ ldd /home/siddharth/tools/tc-java/lib/libjtokyocabinet.so
    libtokyocabinet.so.9 => /home/siddharth/tools/tc/lib/libtokyocabinet.so.9 (0x003dc000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00d1c000)
    libbz2.so.1.0 => /lib/libbz2.so.1.0 (0x007f7000)
    libz.so.1 => /lib/libz.so.1 (0x001d8000)
    librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0x00cd7000)
    libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x00110000)
    libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x00ace000)
    /lib/ld-linux.so.2 (0x0062a000)

And my test program runs perfectly fine now

$ java -Djava.library.path=/home/siddharth/tools/tc-java/lib -classpath ./bin/:lib/tokyocabinet.jar HdbTest
hop
foo:hop
bar:step
baz:jump
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜