Sep 05, 2020 2:21:15 PM com.pi4j.util.NativeLibraryLoader load
SEVERE: Unable to load [libpi4j.so] using path: [/lib/raspberrypi/dynamic/libpi4j.so]
java.lang.UnsatisfiedLinkError: /tmp/libpi4j1709006903530610670.so: /tmp/libpi4j1709006903530610670.so: wrong ELF class: ELFCLASS32
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at com.pi4j.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:159)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:105)
at com.pi4j.wiringpi.Gpio.(Gpio.java:189)
at com.pi4j.io.gpio.RaspiGpioProvider.(RaspiGpioProvider.java:69)
at com.pi4j.io.gpio.RaspiGpioProvider.(RaspiGpioProvider.java:51)
at com.pi4j.platform.Platform.getGpioProvider(Platform.java:125)
at com.pi4j.platform.Platform.getGpioProvider(Platform.java:118)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:109)
at com.pi4j.io.gpio.impl.GpioControllerImpl.(GpioControllerImpl.java:53)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:91)
at LEDBreathingLight.main(LEDBreathingLight.java:29)
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.Gpio.wiringPiSetup()I
at com.pi4j.wiringpi.Gpio.wiringPiSetup(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.(RaspiGpioProvider.java:69)
at com.pi4j.io.gpio.RaspiGpioProvider.(RaspiGpioProvider.java:51)
at com.pi4j.platform.Platform.getGpioProvider(Platform.java:125)
at com.pi4j.platform.Platform.getGpioProvider(Platform.java:118)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:109)
at com.pi4j.io.gpio.impl.GpioControllerImpl.(GpioControllerImpl.java:53)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:91)
at LEDBreathingLight.main(LEDBreathingLight.java:29)
原因:默认加载“libpi4j.so这个文件是32位系统的,需要我们自己生成并修改。
"libpi4j.so"文件的获取方法,请看下面的链接:
https://www.jianshu.com/p/bcc5b87fb71a
处理:修改源码,并打成依赖包(用的eclipse)
源码:https://github.com/Pi4J/pi4j
分析:
位置:com.pi4j.util.NativeLibraryLoader
源码是:System.load(target.toAbsolutePath().toString());
修改成:System.load(new File("libpi4j.so").getAbsolutePath());
然后打包
运行程序的时候要把"libpi4j.so"文件放在类的同目录就可以了。