Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
679 views
in Technique[技术] by (71.8m points)

java - LWJGL: failed to load a library

Have been trying to work with 'lwjgl' on linux and am running into an issue when I run my compiled code from the terminal. I am using the stable release of lwjgl 3.

I downloaded the lwjgl.jar from the website and run the command javac -cp lwjgl.jar: Main.java which compiles the code fine. Then I run: java -cp lwjgl.jar: Main after and it throws this error;

[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)

I'm not sure if I missed some files that I needed too or if I'm going about this entirely the wrong way. Here is the code I am using, it's just some that I found online and I'm using as a test.

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;
        }
    }
}

}

Any help you guys can give would be very much appreciated.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I can only speak from using NetBeans 8 to run LWJGL 3, but I also got the same error. The problem I found had to do with the "native" jar files needing to be added to the "classpath" tab when setting up LWJGL initially. The reason for this is that it enables LWJGL to automatically find the native jars. Then under your VM settings you will want to set it to:

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

Only include quotes if your path name includes any spaces


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...