How to load a java native .jnilib file into a Processing 3.0.1 sketch

edited December 2015 in Library Questions

I recently posted a similar question on the Forum and received some very helpful input but was unable to resolve the issue and may have directed it to the wrong group - so I will try again. I am trying to modify a code written using Eclipse/Proclipsing 4 years ago for a science museum (I am a retired volunteer who has been given this task!). The code interfaces with a digital spectrometer and the spectrometer vendor provides software that support java codes. The desired processing sketch needs to load both .jar and .jnilib files to control the device. The following simple sketch ( a .pde tab and two class tabs) was developed to mimic the techniques need to load these files and the structure of the much more complex exhibit code.

The programming is done using a Mac running OSx 10.9.3 and Processing3.0.1.

The three sketch tabs follow - the first is the .pde file:

    Display display;
    Hardware hardware;
    int rad;
  public void setup() {
    display = new Display(this);
    hardware = new Hardware(this);
    rad = 1;
//    hardware.startWrapper(); // delete this line and the sketch should work!
  public void draw() {
    rad = rad +1;
    if(rad > 300/2){rad = 0;}
  public void settings() {
  public void keyTyped(){
    System.out.println("typed - " + char(key) );
        if (key == 'r') {stroke(255,0,0);}
        if (key == 'b') {stroke(0,0,255);}
        if (key == 'g') {stroke(0,255,0);}

then the two class tabs: class Display

import processing.core.*;

public class Display {
  private PApplet p;
  //public boolean keyState;
  public Display(PApplet p) {
  public void drawCircle(float _radius){


class Hardware

import com.oceanoptics.omnidriver.api.wrapper.Wrapper;
import processing.core.PApplet;

public class Hardware {
  PApplet p;
  Wrapper wrapper = new Wrapper();
  public Hardware(PApplet p) {this.p=p;}

public void startWrapper() {
   System.out.println("trying to find the spectrometer");
   System.out.println (wrapper);
  try {
  catch (UnsatisfiedLinkError e) {
    System.err.println("Native code library failed to load.\n" + e);

  int numberOfSpectrometers = -1;
  numberOfSpectrometers = wrapper.openAllSpectrometers();
  System.out.println (numberOfSpectrometers);

The sketch runs if you comment out the following line in the .pde file :

     hardware.startWrapper(); // delete this line and the sketch should work!

With that line included and a "code" directory in the sketch folder that contains the .jar file for Wrapper and libNatUSB.jnilib file, the sketch does not run and yields the following output.

trying to find the spectrometer
Native code library failed to load.

java.lang.UnsatisfiedLinkError: /Users/westgallery/Desktop/Processing3testing/KeyTypedTest/code/libNatUSB.jnilib: dlopen(/Users/westgallery/Desktop/Processing3testing/KeyTypedTest/code/libNatUSB.jnilib, 1): no suitable image found.  Did find:
    /Users/westgallery/Desktop/Processing3testing/KeyTypedTest/code/libNatUSB.jnilib: no matching architecture in universal wrapper
Could not run the sketch (Target VM failed to initialize).

Any suggestions as to how to deal with the "java.lang.UnsatisfiedLinkError:" error would be greatly appreciated.


Sign In or Register to comment.