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

Trying to develop a sketch using Proc 3.0.1 in Java mode (OSX 10.9.3 and Java 8-65) that needs to use a .jnilib file that contains code that interfaces with an instrument (digital spectrometer) that is connected via the USB.

Followed the recommendation to load the native library: https://www.chilkatsoft.com/java-loadLibrary-MacOSX.asp

and have been unsuccessful. The following provides the sketch and the errors from a debug execution,

for_forum

Note: the .jar files in the "code" folder support the wrapper class in the sketch and are used to see if an instrument is attached... can't get to that point until I can load the libNatUSB.jnilib

In case you can't read the error message on the screen shot : "Native code library failed to load- try again?. java.lang.UnsatisfiedLinkError: /Users/westgallery/Desktop/Processing3testing/OmniDriverTests/code/libNatUSB.jnilib: dlopen(/Users/westgallery/Desktop/Processing3testing/OmniDriverTests/code/libNatUSB.jnilib, 1): no suitable image found. Did find: /Users/westgallery/Desktop/Processing3testing/OmniDriverTests/code/libNatUSB.jnilib: no matching architecture in universal wrapper Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help → Troubleshooting."

Read the revisions and the Help... still stuck!

Any suggestions would be greatly appreciated.

Answers

  • Thank you for taking the time to reply.

    I will give version 3.0a5 a try and see what happens

  • Downloaded ver. 3.0 and got the same unsatisfactory result. Sorry, still not sure I am linking to the native library file correctly, any comments in that regard?

  • Dunno whether v3.0a5 is gonna be of any help. But here's the link for it:
    https://GitHub.com/processing/processing/releases/download/processing-0232-3.0a5/processing-3.0a5-macosx.zip

    Anyways, when using the PDE, we don't put setup() & draw().
    The PDE's pre-processor automatically does that for us! O:-)

  • GoToLoop,

    Thanks again for your input.

    Downloaded 3.0a5 and unfortunately when I try to launch it, it fails with the error dialogue box: Unable to Load Java Runtime Environment. Expect that is due to the fact that version 3.0a5 was released in Nov. 2014 and I am running Java 8-65. If you think the Java version is an issue, what release do you think would be compatible with 3.0a5??

    Also I am confused about your comment regarding set-up() and draw() (though I used loop for this simple test code)?? The PDE may provide a basic template but cannot I simply type my own lines of code for those functions?

    I appreciate your assistance.

  • ... what release do you think would be compatible with 3.0a5??

    All Processing installations come w/ a bundled Java. They don't use the OS' Java.

    Also I am confused about your comment regarding setup() and draw()...

    I was warning about the 1st line of code from your screenshot. :-@

  • Obviously this is new territory for me...

    Thanks for the Java insight, sure that will help me in the future.

    I eliminated the "class" for the .pde (I could explain why I thought it was necessary but that doesn't help right now.) This allowed me to run in two modes "Java" or "Java(2.0)" and would not allow Debug to function for either. Both modes gave the same result and both results were the same as the outcome with 3.0.1 -screenshot follows:

    for_forum2

    Still stuck but will keep trying - very much appreciate your input.

  • When I was "composing" my 2nd reply, somehow I've slipped up what I had to say before the setup() & draw() sentence. So it's turned out incomplete! X_X

    Other observations: Post code as text rather than screenshots, so they can be copied'n'pasted:
    https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text

    The main() function is also automatically generated by PDE's pre-processor.
    So get rid of it as well: https://Processing.org/tutorials/gettingstarted/

  • edited December 2015

    Great input, thanks again ... sorry for any inconvenience due to my inexperience with the forum protocol.

    Quick background - I'm trying to adapt a code that is part of a museum exhibit that was developed with Eclipse/Proclipsing, thus the reason for the weird .pde file - I am a museum "volunteer" with limited java experience but learning each day due to the assistance of people like you!

    Adapted the sketch, shown below, and tried to run it using 3.0a5:

    
    Wrapper wrapper;
    
    void setup() {
        try {
            System.load("/Users/westgallery/Desktop/Processing30a5testing/OmniDriverTests/code/libNatUSB.jnilib");
        }  catch (UnsatisfiedLinkError e)  {
          System.err.println("Native code library failed to load.\n" + e);
          System.exit(1);
        }
    
        wrapper = new Wrapper();
        println (wrapper);
        int numberOfSpectrometers = -1;
        numberOfSpectrometers = wrapper.openAllSpectrometers();
        println (numberOfSpectrometers);
    }
    void draw() { 
    }
    public void settings() {
      size(300, 250);
    }
    
    

    and once the same error in loading the .jnlib file from the code directory - shown below?? The wrapper class is in a .jar file that is also in the sketch's code directory.

    Native code library failed to load. java.lang.UnsatisfiedLinkError: /Users/westgallery/Desktop/Processing30a5testing/OmniDriverTests/code/libNatUSB.jnilib: dlopen(/Users/westgallery/Desktop/Processing30a5testing/OmniDriverTests/code/libNatUSB.jnilib, 1): no suitable image found. Did find: /Users/westgallery/Desktop/Processing30a5testing/OmniDriverTests/code/libNatUSB.jnilib: no matching architecture in universal wrapper Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help → Troubleshooting.

  • Looks like I didn't get the code included correctly in the post - sorry - need to head out... will try again later.

  • edited December 2015

    As mentioned, read this about posting formatted code:
    https://forum.processing.org/two/discussion/8045/how-to-format-code-and-text

    I'm puzzled about the String path argument you pass into System.load():
    "/Users/westgallery/Desktop/..."

    It isn't an absolute full path but a malformed relative 1.
    I believe you should prefix it w/ "C:" in order to turn it an absolute full valid path:
    "C:/Users/westgallery/Desktop/..."

  • I am sure this is frustrating on your end since I'm probably not able to describe the situation effectively... but I am using a Mac running OSX 10.9.3 (Mavericks) and I got the absolute file name from the terminal window for the target directory and the sketch is included below (hopefully correctly formatted).

    I believe the "C:" prefix would be for a Windows system...

    the code still fails the same way:

    java.lang.UnsatisfiedLinkError:

    for this .jnilib file.

    Wrapper wrapper;
    void setup() {
      try {
        System.load("/Users/westgallery/Desktop/Processing30a5testing/OmniDriverTests/code/libNatUSB.jnilib");
      }  
      catch (UnsatisfiedLinkError e) {
        System.err.println("Native code library failed to load.\n" + e);
        System.exit(1);
      }
    
      wrapper = new Wrapper();
      println (wrapper);
      int numberOfSpectrometers = -1;
      numberOfSpectrometers = wrapper.openAllSpectrometers();
      println (numberOfSpectrometers);
    }
    void draw() {
    }
    public void settings() {
      size(300, 250);
    }
    
    

    Prior to posting this question to the Forum I had been working with the software vendor for this instrument and they have no Processing experience but they thought the issue was loading the libNatUSB.jnilib file and that does seem to be the case. Can you recommend another approach to doing this??

    Also I think I have sorted out how to post code... I had tried the leading and following backslash approach but it never worked, it seemed to selectively deal with only some of the lines of code between the backslashes??. So I tried the "pre" "/pre" controllers and it appears to work - Thanks.

  • edited December 2015

    Never did anything as complex as that.
    You may try out your luck by perusing classes System, RunTime & ClassLoader though:

    1. http://docs.Oracle.com/javase/8/docs/api/java/lang/System.html
    2. http://docs.Oracle.com/javase/8/docs/api/java/lang/Runtime.html
    3. http://docs.Oracle.com/javase/8/docs/api/java/lang/ClassLoader.html

    You may also ask about ".jnilib" @ Reddit's subs too:

    1. https://www.Reddit.com/r/javahelp/
    2. https://www.Reddit.com/r/learnjava/
    3. https://www.Reddit.com/r/processing/

    I believe the "C:" prefix would be for a Windows system...

    In order to close the bridge gap among OSes' style paths, rely on sketchPath("") or dataPath(""):

    System.load(sketchPath("code/libNatUSB.jnilib"));

  • edited December 2015

    The sketchPath("") modification yielded the same UnsatisfiedLinkError and provided the exact same path to the file.... so that must not be the issue??

    It will take me more time to see if the other sources you've recommended can provide some insight.

    Thank you very much for your effort and comment.

Sign In or Register to comment.