You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue:
Error running on Windows ...javaxusb\windows\x86_64\libusb4java.dll: Can't find dependent libraries
Root cause:
In windows, lib-javax-usb3 using 02 DLL files (why??): libusb4java.dll and libusb-1.0.dll
But in JNINativeLibraryLoader.load(): Missing code extract and load libusb-1.0.dll.
Solution:
3.1. Long-term: Using one dynamic library for libusb4java => rebuild from C code and JNI/JNA wrapping.
3.2. Short-term:
Add more code to extract libusb-1.0.dll on Windows
Load libusb-1.0.dll first then load libusb4java.dll
Code sample:
`
Path destination = Paths.get(System.getProperty("java.io.tmpdir"), "javaxusb", getOSName(), getOSArch(), getLibraryFilename());
Path destinationDependency = Paths.get(System.getProperty("java.io.tmpdir"), "javaxusb", getOSName(), getOSArch(), "libusb-1.0.dll");
if (!getOSName().contains(OS_WINDOWS) && destination.toFile().exists() && destination.toFile().length() > 0) {
System.load(destination.toString());
return;
}else if(getOSName().contains(OS_WINDOWS) && destinationDependency.toFile().exists() && destinationDependency.toFile().length() > 0){
System.load(destinationDependency.toString());
System.load(destination.toString());
return;
}
Path source = Paths.get(url.toURI());
Logger.getLogger(JNINativeLibraryLoader.class.getName()).log(Level.FINE, "Copy USB native library from {0} to {1}", new Object[]{source, destination});
Logger.getLogger(JNINativeLibraryLoader.class.getName()).log(Level.INFO, "Loading native lib {0}", source);
if (!destination.toFile().exists()){
Files.copy(source, destination);
}
if(getOSName().contains(OS_WINDOWS)){
URL urlDependedWin32 = JNINativeLibraryLoader.class.getClassLoader().getResource("META-INF/nativelib/" + getOSName() + "/" + getOSArch() + "/" + "libusb-1.0.dll");
source = Paths.get(urlDependedWin32.toURI());
Logger.getLogger(JNINativeLibraryLoader.class.getName()).log(Level.FINE, "Copy USB native library from {0} to {1}", new Object[]{source, destination});
Logger.getLogger(JNINativeLibraryLoader.class.getName()).log(Level.INFO, "Loading native lib {0}", source);
if (!destinationDependency.toFile().exists()){
Files.copy(source, destinationDependency);
}
The text was updated successfully, but these errors were encountered:
PeterKieu
changed the title
Windows load missing dependencies
Windows ...javaxusb\windows\x86_64\libusb4java.dll: Can't find dependent libraries
Oct 30, 2019
Error running on Windows ...javaxusb\windows\x86_64\libusb4java.dll: Can't find dependent libraries
In windows, lib-javax-usb3 using 02 DLL files (why??): libusb4java.dll and libusb-1.0.dll
But in JNINativeLibraryLoader.load(): Missing code extract and load libusb-1.0.dll.
3.1. Long-term: Using one dynamic library for libusb4java => rebuild from C code and JNI/JNA wrapping.
3.2. Short-term:
Add more code to extract libusb-1.0.dll on Windows
Load libusb-1.0.dll first then load libusb4java.dll
Code sample:
`
Path destination = Paths.get(System.getProperty("java.io.tmpdir"), "javaxusb", getOSName(), getOSArch(), getLibraryFilename());
Path destinationDependency = Paths.get(System.getProperty("java.io.tmpdir"), "javaxusb", getOSName(), getOSArch(), "libusb-1.0.dll");
if (!getOSName().contains(OS_WINDOWS) && destination.toFile().exists() && destination.toFile().length() > 0) {
System.load(destination.toString());
return;
}else if(getOSName().contains(OS_WINDOWS) && destinationDependency.toFile().exists() && destinationDependency.toFile().length() > 0){
System.load(destinationDependency.toString());
System.load(destination.toString());
return;
}
Path source = Paths.get(url.toURI());
Logger.getLogger(JNINativeLibraryLoader.class.getName()).log(Level.FINE, "Copy USB native library from {0} to {1}", new Object[]{source, destination});
Logger.getLogger(JNINativeLibraryLoader.class.getName()).log(Level.INFO, "Loading native lib {0}", source);
if (!destination.toFile().exists()){
Files.copy(source, destination);
}
if(getOSName().contains(OS_WINDOWS)){
URL urlDependedWin32 = JNINativeLibraryLoader.class.getClassLoader().getResource("META-INF/nativelib/" + getOSName() + "/" + getOSArch() + "/" + "libusb-1.0.dll");
source = Paths.get(urlDependedWin32.toURI());
Logger.getLogger(JNINativeLibraryLoader.class.getName()).log(Level.FINE, "Copy USB native library from {0} to {1}", new Object[]{source, destination});
Logger.getLogger(JNINativeLibraryLoader.class.getName()).log(Level.INFO, "Loading native lib {0}", source);
}
if(getOSName().contains(OS_WINDOWS) ){
System.load(destinationDependency.toString());
System.load(destination.toString());
}else{
System.load(destination.toString());
}
`
The text was updated successfully, but these errors were encountered: