java.lang.UnsatisfiedLinkError - 加载多个 lib 文件?

发布于 2024-10-05 22:47:17 字数 1382 浏览 4 评论 0原文

起初,这个错误对我来说看起来很正常,但是在尝试了所有已知的事情之后,我仍然无法运行我的程序。那么请让我详细解释一下。

我正在尝试在 Ubuntu 上使用 TC 的 java api 运行 TC(TokyoCabinet) 示例。 TC 和 Tc-java 都已正确构建并安装在我的主目录中。 (不是 /usr/local/lib)。

我正在运行程序,例如 -

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

并收到以下错误 -

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)

现在,此错误与符号“tcversion”有关。所以我跑了 -

$ nm /home/siddharth/tools/tc-java/lib/libjtokyocabinet.so.1.1.0  | grep -i tcversion
         U tcversion

这意味着 tcversion 不存在。

实际上 tcversion 位于主 TC 库中

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

现在的问题是,如何使这些库连接起来?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网白 2024-10-12 22:47:17

我想我已经解决了。
这是构建本机 java 库时的一个问题。

我尝试使用

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"

现在 ldd 显示了到 TC 库的正确链接

$ 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)

来重建它并且我的测试程序现在运行得很好

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

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
末蓝 2024-10-12 22:47:17

更好的解决方案是在运行“make”和“make install”之前更改 Makefile。

在 Makefile 中通过

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

在 ld.so.conf.d 下的新 tc.conf 文件中添加 tc 的 lib 目录

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

来替换 LIBS运行 ldconfig

sudo ldconfig -v

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

检查其链接是否正确

$ 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)

运行 TC 的检查

make check

现在安装库

make install

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文