Question

Our team tries to bundle the pi4j-lib as OSGi bundle to access GPIO's on a Raspberry Pi but we getting a UnsatisfiedLinkError and don't know what is happening here and how to solve it.

We put the native libpi4j.so in the folder /lib of the bundle, and specified the MANIFEST.MF like this:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Pi4j
Bundle-SymbolicName: com.pi4j
Bundle-Version: 1.0.0.SNAPSHOT
Bundle-Vendor: http://pi4j.com/
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-NativeCode: lib/libpi4j.so; osname=linux;processor=arm
Eclipse-PlatformFilter: (& (osgi.os=linux) (osgi.arch=arm))
Bundle-ClassPath: lib/, .
Export-Package: com.pi4j.concurrent,[.. some more packages]

This is the Error-Message:

!SESSION 2013-02-10 08:21:25.975 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_40
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=arm, WS=gtk, NL=de_DE

!ENTRY org.eclipse.osgi 4 0 2013-02-10 08:21:37.256
!MESSAGE Application error
!STACK 1
java.lang.UnsatisfiedLinkError: no libpi4j in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1087)
    at com.pi4j.util.NativeLibraryUser.<clinit>(NativeLibraryUser.java:36)
    at eu.gemtec.carepi.app.Application.start(Application.java:30)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)

The Class NativeLibraryUser has a call to System.loadLibrary("libpi4j") to load the native. The native is present in /lib-folder of the bundle so that should be no be the problem. What is happening here, why does it not work?

If I remember right, equinox unpacks the native to the bundle pool in order to load it, but i cant find one for our application, is that a problem?

Was it helpful?

Solution

Use System.loadLibrary("pi4j"). The lib prefix and .so suffix are added automatically as part of the mapping provided by the JVM.

For example on most UNIX systems the above call will load libpi4j.so. However on Mac OS it will be libpi4j.dylib and on Windows it will be pi4j.dll. As a developer you should just specify the root name and allow the JVM to perform the physical mapping.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top