“未定义的符号:__cxa_pure_virtual”在从java加载库时出错。

时间:2022-09-18 11:47:38

I have a Java program that needs to load a native code library (through JNI with SWIG) but when I tried to run it I got an error as follows:

我有一个Java程序需要加载一个本地代码库(通过JNI和SWIG),但是当我尝试运行它时,我有一个错误如下:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/local/lib/libmyapp_jni.so.0.0.0: /usr/local/lib/libmyapp_jni.so.0.0.0: undefined symbol: __cxa_pure_virtual
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
    at java.lang.Runtime.loadLibrary0(Runtime.java:845)
    at java.lang.System.loadLibrary(System.java:1084)
    at org.myapp.myapp.main(myapp.java:11)

by using ldd -d /usr/local/lib/libmyapp_jni.so.0.0.0

通过使用ldd -d /usr/local/lib/libmyapp_jni.so.0.0.0。

$ldd -d /usr/local/lib/libmyapp_jni.so.0
    linux-vdso.so.1 =>  (0x00007ffffedfe000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007feacde2a000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007feacdc26000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007feacda0e000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007feacd7f8000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007feacd42f000)
    /lib64/ld-linux-x86-64.so.2 (0x00007feace5a2000)
undefined symbol: __cxa_pure_virtual    (/usr/local/lib/libmyapp_jni.so.0)
undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE  (/usr/local/lib/libmyapp_jni.so.0)
undefined symbol: _ZTVN10__cxxabiv117__class_type_infoE (/usr/local/lib/libmyapp_jni.so.0)
undefined symbol: _ZTVN10__cxxabiv121__vmi_class_type_infoE (/usr/local/lib/libmyapp_jni.so.0)
undefined symbol: _ZSt7nothrow  (/usr/local/lib/libmyapp_jni.so.0)
undefined symbol: __gxx_personality_v0  (/usr/local/lib/libmyapp_jni.so.0)

I really wonder where went wrong?

我真不知道哪里出了问题?

Any thoughts?

任何想法吗?

Many thanks.

多谢。

1 个解决方案

#1


4  

After rechecking all the answers related to my question on *, I found out the answer by Mark Seaborn to question: What is the purpose of __cxa_pure_virtual? fixed my problem.

在重新检查与*有关的所有答案后,我通过Mark Seaborn找到了答案:__cxa_pure_virtual的目的是什么?解决我的问题。

As my jni library is managed by autotools, after adding "-Wl,--gc-sections -fPIC -shared -lstdc++" to AM_LDFLAGS of Makefile.am problems solved. libstdc++ might not necessary if code is compiled by a c++ compiler (e.g. g++).

正如我的jni库是由autotools管理的,在添加“-Wl,- gc-section -fPIC -shared -lstdc++”到Makefile的AM_LDFLAGS之后。正在解决问题。如果代码是由c++编译器(例如g++)编译的,那么libstdc+可能不是必需的。

Hope this could help others who have the same problem.

希望这能帮助那些有同样问题的人。

#1


4  

After rechecking all the answers related to my question on *, I found out the answer by Mark Seaborn to question: What is the purpose of __cxa_pure_virtual? fixed my problem.

在重新检查与*有关的所有答案后,我通过Mark Seaborn找到了答案:__cxa_pure_virtual的目的是什么?解决我的问题。

As my jni library is managed by autotools, after adding "-Wl,--gc-sections -fPIC -shared -lstdc++" to AM_LDFLAGS of Makefile.am problems solved. libstdc++ might not necessary if code is compiled by a c++ compiler (e.g. g++).

正如我的jni库是由autotools管理的,在添加“-Wl,- gc-section -fPIC -shared -lstdc++”到Makefile的AM_LDFLAGS之后。正在解决问题。如果代码是由c++编译器(例如g++)编译的,那么libstdc+可能不是必需的。

Hope this could help others who have the same problem.

希望这能帮助那些有同样问题的人。