Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PeterKieu opened this issue Oct 30, 2019 · 1 comment

Comments

@PeterKieu
Copy link

PeterKieu commented Oct 30, 2019

  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());
    }
    `

@PeterKieu PeterKieu changed the title Windows load missing dependencies Windows ...javaxusb\windows\x86_64\libusb4java.dll: Can't find dependent libraries Oct 30, 2019
@niushapaks
Copy link

niushapaks commented Nov 3, 2020

Works perfectly, thanks !

niushapaks added a commit to niushapaks/lib-javax-usb3 that referenced this issue Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants