6

I'm using NetBeans on MacOS to develop an application using PI4J. Everything looks Ok but I get the error below, saying that PI4J was unable to load. Does anyone know how to solve this?

abr 18, 2015 3:02:30 PM com.pi4j.util.NativeLibraryLoader load
SEVERE: Unable to load [libpi4j.so] using path: [/lib/libpi4j.so]
java.lang.UnsatisfiedLinkError: /private/var/folders/0x/6rph2scs0f544b7xwkfhzkcw0000gn/T/libpi4j3968879292977354112.so: dlopen(/private/var/folders/0x/6rph2scs0f544b7xwkfhzkcw0000gn/T/libpi4j3968879292977354112.so, 1): no suitable image found.  Did find:
    /private/var/folders/0x/6rph2scs0f544b7xwkfhzkcw0000gn/T/libpi4j3968879292977354112.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1822)
    at java.lang.Runtime.load0(Runtime.java:809)
    at java.lang.System.load(System.java:1086)
    at com.pi4j.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:143)
    at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:92)
    at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:174)
    at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:51)
    at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
    at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
    at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
    at hellorasp.HelloRasp.main(HelloRasp.java:31)

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.<init>(RaspiGpioProvider.java:51)
    at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
    at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:54)
    at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
    at hellorasp.HelloRasp.main(HelloRasp.java:31)
yglodt
  • 13,807
  • 14
  • 91
  • 127
Carlos
  • 170
  • 1
  • 3
  • 11
  • related: http://stackoverflow.com/questions/9832862/running-jad-file-in-mac-osx-lion –  Apr 20 '15 at 11:26

5 Answers5

2
sudo apt-get remove wiringpi -y
sudo apt-get --yes install git-core gcc make
cd ~
git clone https://github.com/WiringPi/WiringPi --branch master --single-branch wiringpi
cd ~/wiringpi
sudo ./build

This is taken from pi4j I faced this issue and when I executed these lines in terminal...everything worked perfectly

TT.
  • 15,774
  • 6
  • 47
  • 88
  • The official WiringPi project was deprecated and lacks support for the Raspberry Pi 4/400/CM4. A fork is available on GitHub in the repo mentioned in this answer, with some improvements to fix this. More info is available on https://pi4j.com/1.4/dependency.html – Frank Dec 01 '21 at 06:32
1

/lib/libpi4j.so file will not work because it is tailored just for Raspberry Pi, not any other hardware.

1

I faced the same issue working with Raspberry P4, java 11 and pi4j v2. I solved it downloading pigpio library directly from the raspberry

sudo apt-get install pigpio

After the library was installed, the jar worked perfecrly

  • 1
    It seems we are missing some documentation on the Pi4J website regarding the need to install pigpio itself as this only needs to be done in certain cases. I would like to understand your approach Roberto, what steps you took, etc. so I can extend the documentation. Would be great if you could share here or via https://github.com/Pi4J/pi4j-v2/discussions – Frank Feb 09 '22 at 06:27
-1

just copy libpi4j.so to your project lib folder on RPI

Tadas B.
  • 176
  • 8
-1

assuming the OP is running his code on a raspberry pi, I also got this error on a pi running code that controlled servos that worked as of Feb-2018 but produced this exact error in Jul-2018. I found a change in the pi4j 1.2 distro needs you to install the wiringpi library manually

so i got that exact error, followed these instructions and my servos are moving again:

http://wiringpi.com/download-and-install/

bsautner
  • 4,479
  • 1
  • 36
  • 50