简体   繁体   English

LWJGL'java.lang.UnsatisfiedLinkError':java.library.path中没有lwjgl

[英]LWJGL 'java.lang.UnsatisfiedLinkError': no lwjgl in java.library.path

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr
ary.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at org.lwjgl.Sys$1.run(Sys.java:73)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
        at org.lwjgl.Sys.loadLibrary(Sys.java:95)
        at org.lwjgl.Sys.<clinit>(Sys.java:112)
        at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
        at org.lorana.client.Lorana.<init>(Lorana.java:20)
        at org.lorana.client.Lorana.main(Lorana.java:31)

The error still persists after I've linked all native libraries to every referenced library, and followed the instructions of http://ninjacave.com/lwjglwitheclipse 将所有本机库链接到每个引用的库,并按照http://ninjacave.com/lwjglwitheclipse的说明进行操作后,错误仍然存​​在。

I've also followed other questions on the board regarding lwjgl unsatisfiedlinkerrors, but to no avail. 我还关注了板上有关lwjgl不满意的链接错误的其他问题,但无济于事。

Would very much appreciate the help, Thanks in advance! 非常感谢您的帮助,在此先感谢!

LWJGL uses its own variables for the path to the native libraries: LWJGL使用其自己的变量作为本机库的路径:

 System.setProperty("org.lwjgl.librarypath", new File("pathToNatives").getAbsolutePath());


If you kept the file structure from the LWJGL package you can use something like this: 如果您保留了LWJGL软件包中的文件结构,则可以使用以下内容:

    switch(LWJGLUtil.getPlatform())
    {
        case LWJGLUtil.PLATFORM_WINDOWS:
        {
            JGLLib = new File("./native/windows/");
        }
        break;

        case LWJGLUtil.PLATFORM_LINUX:
        {
            JGLLib = new File("./native/linux/");
        }
        break;

        case LWJGLUtil.PLATFORM_MACOSX:
        {
            JGLLib = new File("./native/macosx/");
        }
        break;
    }

    System.setProperty("org.lwjgl.librarypath", JGLLib.getAbsolutePath());

Not sure about getting it to work in Eclipse BUT I encountered similar problems in my attempt to build an executable JAR. 不确定如何使其在Eclipse中运行,但在尝试构建可执行JAR时遇到了类似的问题。

All of the solutions below assume you have the native libraries either alongside the JAR file in the same directory, or bundled into the JAR as embedded resources. 以下所有解决方案均假定您在同一目录中的JAR文件旁边拥有本机库,或者将其作为嵌入式资源捆绑到JAR中。

As @Dawnkeeper describes , you can simply use the "org.lwjgl.librarypath" system property to instruct LWJGL where to find the native libraries. 正如@Dawnkeeper 所描述的 ,您可以简单地使用“ org.lwjgl.librarypath”系统属性来指示LWJGL在哪里找到本机库。

OR 要么

As your error suggests, LWJGL checks the more-common "java.library.path" system property to locate the native libraries. 就像您的错误所暗示的那样,LWJGL检查更常见的“ java.library.path”系统属性以查找本机库。 You can set this at the command line when you run your JAR like so: 您可以在运行JAR时在命令行中进行设置,如下所示:

java -Djava.library.path=./lib -jar myApplication.jar

As I mentioned above though, I wanted a stand-alone executable JAR; 如前所述,我想要一个独立的可执行JAR。 I didn't want the user to have to run the JAR file with command-line arguments. 我不希望用户必须使用命令行参数来运行JAR文件。 I attempted to set this system property from within my main method but soon discovered that you cannot change this system property's value after the JVM runtime has been initialized . 我试图从我的main方法中设置此系统属性,但是很快发现在初始化JVM运行时后您无法更改此系统属性的值 Instead, I ended up writing the following code (using the work-around linked above) to set the "java.library.path" within my main method: 相反,我最终编写了以下代码(使用上面的替代方法)来在我的main方法中设置“ java.library.path”:

public static void main(String[] args) {
    addLwjglNativesToJavaLibraryPathProperty();
    // run code dependent on LWJGL here...
}

private static void addLwjglNativesToJavaLibraryPathProperty() {
    String osDir;
    if (SystemUtils.IS_OS_WINDOWS) {
        osDir = "windows";
    } else if (SystemUtils.IS_OS_LINUX) {
        osDir = "linux";
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        osDir = "macosx";
    } else if (SystemUtils.IS_OS_SOLARIS) {
        osDir = "solaris";
    } else {
        throw new RuntimeException("Unsupported OS: " + System.getProperty("os.name"));
    }
    addPathToJavaLibraryPathProperty("lib/natives/" + osDir);
}

// https://stackoverflow.com/q/5419039
private static void addPathToJavaLibraryPathProperty(String propertyValue) {
    String propertyName = "java.library.path";
    try {
        Field field = ClassLoader.class.getDeclaredField("usr_paths");
        field.setAccessible(true);
        String[] paths = (String[]) field.get(null);
        for (String path : paths) {
            if (propertyValue.equals(path)) return;
        }
        String[] tmp = new String[paths.length + 1];
        System.arraycopy(paths, 0, tmp, 0, paths.length);
        tmp[paths.length] = propertyValue;
        field.set(null, tmp);
        System.setProperty(propertyName, System.getProperty(propertyName) + File.pathSeparator + propertyValue);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Failed to get permissions to set " + propertyName);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException("Failed to get field handle to set " + propertyName);
    }
}

Code Reference: https://code.google.com/p/gwahtzee/source/browse/trunk/src/main/java/com/googlecode/gwahtzee/Application.java 代码参考: https : //code.google.com/p/gwahtzee/source/browse/trunk/src/main/java/com/googlecode/gwahtzee/Application.java

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取“java.lang.UnsatisfiedLinkError”:java.library.path 中没有 lwjgl - Getting 'java.lang.UnsatisfiedLinkError': no lwjgl in java.library.path LWJGL Applet java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl - LWJGL Applet java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path 臭名昭著的“java.lang.UnsatisfiedLinkError:java.library.path 中没有 lwjgl64” - Infamous "java.lang.UnsatisfiedLinkError: no lwjgl64 in java.library.path" 线程“main”中的异常java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl - Exception in thread “main” java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path 线程“ main”中的异常java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl-devil - Exception in thread “main” java.lang.UnsatisfiedLinkError: no lwjgl-devil in java.library.path java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl,但是设置了本机 - java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path but natives are set “ java.library.path中没有lwjgl” - “no lwjgl in java.library.path” java.lang.UnsatisfiedLinkError:否 <LIBRARY> 在java.library.path中 - java.lang.UnsatisfiedLinkError: no <LIBRARY> in java.library.path java.lang.UnsatisfiedLinkError:cqjnilinuxproxy(在java.library.path中找不到) - java.lang.UnsatisfiedLinkError: cqjnilinuxproxy (Not found in java.library.path) java.lang.UnsatisfiedLinkError: java.library.path 中没有 jhdf5 - java.lang.UnsatisfiedLinkError: no jhdf5 in java.library.path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM