Skip to content

Windows ...javaxusb\windows\x86_64\libusb4java.dll: Can't find dependent libraries #1

Description

@PeterKieu
  1. Issue:
    Error running on Windows ...javaxusb\windows\x86_64\libusb4java.dll: Can't find dependent libraries
  2. 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.
  3. 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);
      }
    

    }
    if(getOSName().contains(OS_WINDOWS) ){
    System.load(destinationDependency.toString());
    System.load(destination.toString());
    }else{
    System.load(destination.toString());
    }
    `

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions