简体   繁体   中英

“Unable to load library: JNA native support not found in resource path” on trying to load JNA library on Mac OS X

I have a JNA library stub like this:

public interface FREngine extends Library {
    NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance("FREngine");
    FREngine INSTANCE = (FREngine) Native.loadLibrary("FREngine", FREngine.class);
}

If I try to use this library in any way, I get a really confusing error:

java.lang.UnsatisfiedLinkError: Unable to load library 'FREngine': 
    JNA native support (darwin/libFREngine.jnilib) not found in resource path 
    (...entire classpath here...)

Why this is confusing to me:

  • .jnilib is the file extension for JNI libraries. Since I'm using JNA, I wouldn't expect JNA to be using any JNI library other than its own one, "jnidispatch".
  • JNA is looking on the classpath for this file, but there is no way in hell it will be there because it's just some random library I'm trying to import. Shouldn't it be looking on DYLD_FRAMEWORK_PATH ?
  • Other native libraries which are initialised in exactly the same way work fine. For instance, CoreFoundation can be resolved. Its code for loading the library is the same aside from the name of the library being different.

I tried looking at the frameworks themselves and can only see minor differences:

  • FREngine.framework is in /Library , CoreFoundation.framework is in /System/Library
  • FREngine.framework/Versions contains a directory with a longer and more complex name than CoreFoundation.framework , which only has one version called A .
  • FREngine.framework/Versions/[ver] contains Headers and Libraries

The version of JNA in use is 3.5.2. We can't upgrade to 4.x because there is some other bug which causes an exception as soon as we try to load our native library.

The reason why FREngine library does not work in this case in a wrong Engine load method. FREngine is expected to be loaded via com.abbyy.FREngine only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM