java调用so库问题记录

遇到的问题

  1. 加载libnvssdk. so不成功
  2. /lib64/libstdc++.so.6: version 'GLIBCXX 3.4.21'found (required by libnvssdk. so
  3. NetClient_LoadOsCore::LoadOSSDK fail!
  4. java.lang.IllegalArgumentException: Invalid Structure field in class NVSSDK$NetPicPara NVSSDK$NET_PICSTREAM_NOTIFY" is not supported: Native size for type NVSSDK$NET_PICSTREAM_NOTIFY" is unknown

 解决办法

目录

1.加载libnvssdk. so不成功

2、/lib64/libstdc++.so.6: version 'GLIBCXX 3.4.21'found (required by libnvssdk. so

3.NetClient_LoadOsCore::LoadOSSDK fail!

4.java.lang.IllegalArgumentException: Invalid Structure field in class


1.加载libnvssdk. so不成功

将厂家给的sdk放到系统lib目录下

自定lib目录时,需要在代码里使用绝对路径加载sdk:

Native.loadLibrary("/root/sdk/libnvssdk.so",NVSSDK.class)

针对找不到这个问题基本上都能解决了,但是可能因为系统依赖的原因,也会导致加载so不成功!

查看目标操作系统是否能满足厂家给的sdk,使用ldd命令查看被加载的so是否可以正常使用:

ldd /root/libnvssdk.so

依赖正常会有如下输出:


[root@localhost ~]# ldd /root/sdk/libnvssdk.so
        linux-vdso.so.1 =>  (0x00007ffe65de4000)
        librt.so.1 => /lib64/librt.so.1 (0x00007ff558ffa000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007ff558df6000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007ff558a7c000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff55877a000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff558564000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff558196000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff557f7a000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff559b16000)
[root@localhost ~]#

依赖异常:/root/sdk/libnvssdk .so:/lib64/libstdc++.so.6: version 'GLIBCXX 3.4.21' not found (required by/root/sdk/libnvssdk.so

[root@localhost ~]# ldd /root/sdk/libnvssdk.so
/root/sdk/libnvssdk .so:/lib64/libstdc++.so.6: version 'GLIBCXX 3.4.21' not found (required by/root/sdk/libnvssdk.so
        linux-vdso.so.1 =>  (0x00007ffe65de4000)
        librt.so.1 => /lib64/librt.so.1 (0x00007ff558ffa000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007ff558df6000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007ff558a7c000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff55877a000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff558564000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff558196000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff557f7a000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff559b16000)
[root@localhost ~]#

出现如上异常请参考本人这篇文章centos 7升级gcc到10.5.0

2、/lib64/libstdc++.so.6: version 'GLIBCXX 3.4.21'found (required by libnvssdk. so

 出现该问题表示系统gcc版本太低,请参考本人这篇文章centos 7升级gcc到10.5.0

3.NetClient_LoadOsCore::LoadOSSDK fail!

出现这个问题时我得项目中的libnvssdk. so这个已经加载成功,看到该问题第一想到的是厂家给的sdk不对版,结果很现实厂家给的东西没错,但是也有错,说他有错是因为我是用的绝对路径加载的so文件,按理说其他的库应该也是默认使用我的据对路径,结果不然,其他的库还是去系统默认及自定义环境变量中去寻找。哈哈!

添加自定义sdk库的路径到环境变量中

vim /etc/profile
export LD_LIBRARY_PATH=/root/sdk

source /etc/profile

4.java.lang.IllegalArgumentException: Invalid Structure field in class

详细问题输出:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: java.lang.IllegalArgumentException: Invalid Structure field in class com.test.NVSSDK$NetPicPara, field name 'cbkPicStreamNotify' (interface com.test.NVSSDK$NET_PICSTREAM_NOTIFY): The type "com.test.NVSSDK$NET_PICSTREAM_NOTIFY" is not supported: Native size for type "com.test.NVSSDK$NET_PICSTREAM_NOTIFY" is unknown
        at com.sun.jna.Structure.validateField(Structure.java:1109)
        at com.sun.jna.Structure.validateFields(Structure.java:1119)
        at com.sun.jna.Structure.(Structure.java:179)
        at com.sun.jna.Structure.(Structure.java:172)
        at com.sun.jna.Structure.(Structure.java:159)
        at com.sun.jna.Structure.(Structure.java:151)
        at com.test.TianDiSdkStructure.(TianDiSdkStructure.java:17)
        at com.test.NVSSDK$NetPicPara.(NVSSDK.java:313)
        at com.test.VcaSnap.StartSnap(VcaSnap.java:427)
        at com.test.VcaSnap.main(VcaSnap.java:473)
        ... 8 more
Caused by: java.lang.IllegalArgumentException: The type "com.test.NVSSDK$NET_PICSTREAM_NOTIFY" is not supported: Native size for type "com.test.NVSSDK$NET_PICSTREAM_NOTIFY" is unknown
        at com.sun.jna.Native.getNativeSize(Native.java:1180)
        at com.sun.jna.Structure.getNativeSize(Structure.java:2072)
        at com.sun.jna.Structure.getNativeSize(Structure.java:2062)
        at com.sun.jna.Structure.validateField(Structure.java:1105)
        ... 17 more

在代码中找到对应的报错信息将 extends StdCallCallback 改为 extends Callback 注意Callback为com.sun.Callback

你可能感兴趣的:(java,开发语言)