NicholasAStuart / myo-java

Java API for Thalmic's Myo Device
Apache License 2.0
41 stars 27 forks source link

Library not working with OS X. #5

Closed suchintan closed 9 years ago

suchintan commented 9 years ago

Hi,

I tried using your library on OS X and it kept giving me the following errors:

java.lang.UnsatisfiedLinkError: no myo in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1088)
    at com.thalmic.myo.Hub.copyAndLoadOSXFromTemp(Hub.java:123)
    at com.thalmic.myo.Hub.loadJniResources(Hub.java:60)
    at com.thalmic.myo.Hub.<init>(Hub.java:24)
    at com.thalmic.myo.example.HelloMyo.main(HelloMyo.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Unable to load myo64.dll from directory /var/folders/r2/6sjpbgvn24g9smp_25jxmhqc0000gn/T.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could Not Load myo and myo-java libs
    at com.thalmic.myo.Hub.loadJniResources(Hub.java:62)
    at com.thalmic.myo.Hub.<init>(Hub.java:24)
    at com.thalmic.myo.example.HelloMyo.main(HelloMyo.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

I dug a little deeper and found that the Hub.java class was going into the copyAndLoadOSXFromTemp method. Within this method, it was successfully copying the myo.framework and libmyo.jnilib files into java.library.path. I evaluated this by observing the directory structure during runtime using this:

String property = System.getProperty("java.library.path");
StringTokenizer parser = new StringTokenizer(property, ";");
File f = new File(parser.nextToken());
for(File fi : f.listFiles()){
     System.out.println(fi.getName());
}

But through all of that, it still gives the exception above.

Perhaps I'm doing something wrong or I missed a step? I'm relatively unfamiliar with System.getProperty to load properties, so I can't say for sure why it's failing to read the properties given.

NicholasAStuart commented 9 years ago

The Unable to load myo64.dll from directory is a typo, I'll fix that, but as for why you cannot load, I'm not sure. Can you add the following JVM arguments:

 -Xcheck:jni
 -XX:+ShowMessageBoxOnError
 -XX:+UseOSErrorReporting
suchintan commented 9 years ago

I'm getting these errors now:

java.lang.UnsatisfiedLinkError: /private/var/folders/r2/6sjpbgvn24g9smp_25jxmhqc0000gn/T/libmyo.jnilib: dlopen(/private/var/folders/r2/6sjpbgvn24g9smp_25jxmhqc0000gn/T/libmyo.jnilib, 1): Library not loaded: @rpath/myo.framework/Versions/A/myo
  Referenced from: /private/var/folders/r2/6sjpbgvn24g9smp_25jxmhqc0000gn/T/libmyo.jnilib
  Reason: image not found
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1894)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1880)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1088)
    at com.thalmic.myo.Hub.copyAndLoadOSXFromTemp(Hub.java:123)
    at com.thalmic.myo.Hub.loadJniResources(Hub.java:60)
    at com.thalmic.myo.Hub.<init>(Hub.java:24)
    at com.thalmic.myo.example.HelloMyo.main(HelloMyo.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Unable to load myo64.dll from directory /var/folders/r2/6sjpbgvn24g9smp_25jxmhqc0000gn/T.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could Not Load myo and myo-java libs
    at com.thalmic.myo.Hub.loadJniResources(Hub.java:62)
    at com.thalmic.myo.Hub.<init>(Hub.java:24)
    at com.thalmic.myo.example.HelloMyo.main(HelloMyo.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
suchintan commented 9 years ago

So it appears to recognise the jni libraries but still fails to load them.

NicholasAStuart commented 9 years ago

What version of OSX are you using? Can you put a breakpoint at line 111 and examine where the files are being copied to and whether they are are actually copied there? Breakpoint, examine the TEMP_DIRECTORY_LOCATION variable for the location, then do a ls there to verify that libmyo.jnilib is copied correctly.

0xSalman commented 9 years ago

Hey,

I am having the same issue when I run the sample code. I get the same stack trace as the above user. I added a break point and was able to find libmyo.jnilib in TEMP_DIRECTORY_LOCATION. My OS X version is 10.9.5. I would appreciate quick help, thank you.

suchintan commented 9 years ago

Same here - the files are also present for me. I'm also using OS X 10.9.5.

NicholasAStuart commented 9 years ago

Not sure what to tell you. I'm working on 10.10 OSX currently, and don't have the ability to work on 10.9.5, but I believe others have gotten it working on there as well.

NicholasAStuart commented 9 years ago

@suchintan @msalman86 have you had any luck? I'm not sure as OSX isn't my primary OS, but might it have to do with the fact that I compiled it on OSX 10.10? If you felt bold enough, you could download the JNI library and compile it yourself.

0xSalman commented 9 years ago

@NicholasAStuart, thanks for your feedback. I did compile JNI library myself and that didn't work either. It seems there's something up with "rpath" lookup. I will play around with this when I get some free time.

NicholasAStuart commented 9 years ago

@msalman86 The @rpath is OSX's way of setting a path relative to the loaded program.

pawegio commented 9 years ago

Same error on OS X 10.9.5:

Unable to load myo from system directories.
Unable to load libmyo.jnilib from directory /var/folders/8q/qcw3sl8j1ms2z0zk35d9k1th0000gn/T
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could Not Load myo and myo-java libs
    at com.thalmic.myo.Hub.loadJniResources(Hub.java:53)
    at com.thalmic.myo.Hub.<init>(Hub.java:23)
    at Main.main(Main.java:8)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
NicholasAStuart commented 9 years ago

@pawegio Can you verify that the directory is getting copied over to that temp directory?

pawegio commented 9 years ago

Inside /var/folders/8q/qcw3sl8j1ms2z0zk35d9k1th0000gn/T I found myo.framework

pawegio commented 9 years ago

Today I switched to OS X 10.10, but error still occurs.

When I passed to VM options: -Djava.library.path="/Users/pawegio/Workspace/myo-java/src/main/resources/osx"

I received:

java.lang.UnsatisfiedLinkError: /Users/pawegio/Workspace/myo-java/src/main/resources/osx/libmyo.jnilib: dlopen(/Users/pawegio/Workspace/myo-java/src/main/resources/osx/libmyo.jnilib, 1): Library not loaded: @rpath/myo.framework/Versions/A/myo
  Referenced from: /Users/pawegio/Workspace/myo-java/src/main/resources/osx/libmyo.jnilib
  Reason: no suitable image found.  Did find:
    /Users/pawegio/Workspace/myo-java/src/main/resources/osx/myo.framework/Versions/A/myo: code signature invalid for '/Users/pawegio/Workspace/myo-java/src/main/resources/osx/myo.framework/Versions/A/myo' 

EDIT:

Same on Windows OS after System.loadLibrary("JNIJavaMyoLib64"); I have:

Can't find dependent libraries.

NicholasAStuart commented 9 years ago

@pawegio Can you try the newest version?

EricZeiberg commented 9 years ago

I am getting the same error.

Unable to load myo from system directories. Unable to load libmyo.jnilib from directory /var/folders/vd/2nmp_9px2wgfdvmx9zxnl4_m0000gn/T Exception in thread "main" java.lang.UnsatisfiedLinkError: Could Not Load myo and myo-java libs at com.thalmic.myo.Hub.loadJniResources(Hub.java:53) at com.thalmic.myo.Hub.<init>(Hub.java:23) at com.thalmic.myo.example.HelloMyo.main(HelloMyo.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Running OSX 10.10 Yosemite

NicholasAStuart commented 9 years ago

@MasterEjay Unfortunately these are hard for me to diagnose. Can you try clearing out that temp directory, and ensuring that the directory is getting copied over? Are you using version 0.8.1?

suchintan commented 9 years ago

I got myo to work on OSX by using the Websocket layer (ws://127.0.0.1:10138/myo/3) along with the Java-Websocket library. For any of you that want to try it out, the docs are located here: https://developer.thalmic.com/forums/topic/534/

NicholasAStuart commented 9 years ago

I'm now seeing this on my machine. Apparently this is a problem with code signatures, I'm not sure if it's on the end of the myo library or my own. I'll continue to investigate this.

NicholasAStuart commented 9 years ago

@suchintan @MasterEjay @pawegio @msalman86

Please try to 0.8.2 version that is now available on Maven Central. It should fix the issues you all have been having. The issue was from the myo library not copying over correctly, and I believe I have solved this now.

MKnierim commented 7 years ago

Hey everyone,

has this been fixed definitely? I still encounter the error that the library could not be found. Working on OS X 10.11.6 using the latest version of the sdk, but no success... :(

Best regards Michael