native-lib-loader icon indicating copy to clipboard operation
native-lib-loader copied to clipboard

extractRegistered prompts java.io.FileNotFoundException for extracted dependency

Open cafhach opened this issue 5 years ago • 1 comments

For my native library, I need to extract some native dependencies and I wanted to use NativeLoader.extractRegistered() for that. I put all of them into a jar and listed the sonames in META-INF/lib/linux_64/. From the log output below I'm guessing that the first dependency libifcoremt.so.5 is successfully extracted to the temporary dir but then something goes wrong. Is the temporary directory deleted too early?

content of META-INF/lib/linux_64/AUTOEXTRACT.LIST

linux_64/libifcoremt.so.5
linux_64/libifport.so.5
linux_64/libimf.so
linux_64/libintlc.so.5
[etc.]

initialization code

  static {    
    try {
      NativeLoader.extractRegistered();
      NativeLibraryUtil.loadNativeLibrary(MyLibJNI.class, "mylib");
    } catch (IOException e) {
      System.err.println("NativeLoader failed to load library. \n" + e);
      System.exit(1);
    }
  }

Log output

5028 [main] DEBUG org.scijava.nativelib.BaseJniExtractor - Extracting libraries registered in classloader sun.misc.Launcher$AppClassLoader@6d6f6e28
5030 [main] DEBUG org.scijava.nativelib.BaseJniExtractor - Extracting libraries listed in file:/home/me/src/trunk/native-intel-runtime/target/classes/META-INF/lib/linux_64/AUTOEXTRACT.LIST
5032 [main] DEBUG org.scijava.nativelib.BaseJniExtractor - Extracting 'file:/home/me/src/trunk/native-intel-runtime/target/classes/natives/linux_64/libifcoremt.so.5' to '/tmp/nativelib-loader_1434383826253268890/linux_64/libifcoremt.so.5'
NativeLoader failed to load library. 
java.io.FileNotFoundException: /tmp/nativelib-loader_1434383826253268890/linux_64/libifcoremt.so.5 (No such file or directory)

cafhach avatar Feb 04 '19 15:02 cafhach

Maybe it makes sense to step through in a debugger so that you can see which files are there when during the code's execution, and inspect those files using ldd etc. to make sure they are well-formed and functional from the temp folder?

Sorry I don't have more insight. If you figure it out and file a PR, I'll try to review / merge / release the fix ASAP.

ctrueden avatar Feb 19 '19 22:02 ctrueden