java - LWJGL:加载库失败

标签 java lwjgl

一直在尝试在 Linux 上使用“lwjgl”,但在从终端运行编译后的代码时遇到了问题。我正在使用 lwjgl 3 的稳定版本。

我从网站上下载了 lwjgl.jar 并运行命令 javac -cp lwjgl.jar: Main.java 可以很好地编译代码。然后我运行:java -cp lwjgl.jar: Main 然后它抛出这个错误;

[LWJGL] Failed to load a library. Possible solutions:
    a) Set -Djava.library.path or -Dorg.lwjgl.librarypath to the directory that contains the shared libraries.
    b) Add the JAR(s) containing the shared libraries to the classpath.
[LWJGL] Enable debug mode with -Dorg.lwjgl.util.Debug=true for better diagnostics.
Exception in thread "EndlessRunner" java.lang.UnsatisfiedLinkError: Failed to locate library: liblwjgl.so
    at org.lwjgl.system.Library.loadSystemRelative(Library.java:100)
    at org.lwjgl.system.Library.loadSystem(Library.java:71)
    at org.lwjgl.system.Library.<clinit>(Library.java:43)
    at org.lwjgl.system.MemoryAccess.<clinit>(MemoryAccess.java:17)
    at org.lwjgl.system.Pointer.<clinit>(Pointer.java:22)
    at org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:562)
    at Main.init(Main.java:31)
    at Main.run(Main.java:78)
    at java.lang.Thread.run(Thread.java:745)

我不确定我是否遗漏了一些我需要的文件,或者我是否以完全错误的方式处理这件事。这是我正在使用的代码,它只是我在网上找到的一些代码,我将其用作测试。

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
import java.nio.ByteBuffer;
import org.lwjgl.glfw.GLFWVidMode;

public class Main implements Runnable{

private Thread thread;
public boolean running = true;

private long window;

private int width = 1200, height = 800;

public static void main(String args[]){
    Main game = new Main();
    game.start();
}

public void start(){
    running = true;
    thread = new Thread(this, "EndlessRunner");
    thread.start();
}

public void init(){
    // Initializes our window creator library - GLFW 
    // This basically means, if this glfwInit() doesn't run properlly
    // print an error to the console
    if(glfwInit() != true){
        // Throw an error.
        System.err.println("GLFW initialization failed!");
    }

    // Allows our window to be resizable
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);

    // Creates our window. You'll need to declare private long window at the
    // top of the class though. 
    // We pass the width and height of the game we want as well as the title for
    // the window. The last 2 NULL parameters are for more advanced uses and you
    // shouldn't worry about them right now.
    window = glfwCreateWindow(width, height, "Endless Runner", NULL, NULL);

    // This code performs the appropriate checks to ensure that the
    // window was successfully created. 
    // If not then it prints an error to the console
    if(window == NULL){
        // Throw an Error
        System.err.println("Could not create our Window!");
    }

    // creates a bytebuffer object 'vidmode' which then queries 
    // to see what the primary monitor is. 
    //ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    // Sets the initial position of our game window. 
    glfwSetWindowPos(window, 100, 100);
    // Sets the context of GLFW, this is vital for our program to work.
    glfwMakeContextCurrent(window);
    // finally shows our created window in all it's glory.
    glfwShowWindow(window);
}

public void update(){
    // Polls for any window events such as the window closing etc.
    glfwPollEvents();
}

public void render(){
    // Swaps out our buffers
    glfwSwapBuffers(window);
}

@Override
public void run() {
    // All our initialization code
    init();
    // Our main game loop
    while(running){
        update();
        render();
        // Checks to see if either the escape button or the
        // red cross at the top were pressed.
        // if so sets our boolean to false and closes the
        // thread.
        if(glfwWindowShouldClose(window) == true){
            running = false;
        }
    }
}

非常感谢你们能提供的任何帮助。

谢谢。

最佳答案

我只能说使用 NetBeans 8 来运行 LWJGL 3,但我也遇到了同样的错误。我发现的问题与最初设置 LWJGL 时需要添加到“类路径”选项卡的“ native ”jar 文件有关。这样做的原因是它使 LWJGL 能够自动找到 native jar。然后在您的 VM 设置下,您需要将其设置为:

-Djava.library.path="Path to where you extracted JAR files"

如果您的路径名包含任何空格,则仅包含引号

关于java - LWJGL:加载库失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38934607/

相关文章:

java - Opengl 渲染 - z 范围 -1 到 1 之外的任何内容都不会出现?

使用 lwjgl 的 Java 高度图

java - LWJGL:无法在 opengl 中渲染多个形状

java - Spring FileSystemXmlApplicationContext getBeanDefinitionNames 返回空数组

java - 无法点击 Android 移动应用程序上 textview 消息内的链接 - Appium

java - 使用java和google app引擎解压缩sp上传的zip文件中的特定文件

java - 求多项式的导数(无效版本)

java - 绘制文本(字符串)时出现问题

java - 出现此错误消息的原因可能是什么?

java - 避免在加密和编码的 URL 字符串中换行