2016-08-13 6 views
3

Ich habe versucht, mit 'lwjgl' unter Linux zu arbeiten und stoße auf ein Problem, wenn ich meinen kompilierten Code vom Terminal aus starte. Ich bin mit dem stabilen Release von lwjgl 3.LWJGL: Bibliothek konnte nicht geladen werden

ich die lwjgl.jar von der Website heruntergeladen und führen Sie den Befehl javac -cp lwjgl.jar: Main.java , die den Code fein kompiliert. Dann starte ich: java -cp lwjgl.jar: Main nach und es wirft diesen Fehler;

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

Ich bin mir nicht sicher, ob ich einige Dateien verpasst, die ich auch gebraucht oder wenn ich darüber werde völlig der falsche Weg. Hier ist der Code, den ich verwende, es sind nur einige, die ich online gefunden habe und die ich als Test verwende.

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

}

Jede Hilfe euch geben können, würde sehr geschätzt.

Danke.

+1

Im Allgemeinen ist der Fehler sehr häufig und Ihre Beschreibung nicht sehr spezifisch. Wie die Nachricht sagt: Es konnte die native Bibliothek nicht finden. Beachten Sie, dass * zusätzlich * zur JAR ** auch ** die Datei 'liblwjgl.so' benötigt wird (die im ZIP-Paket enthalten ist, das Sie von der Website heruntergeladen haben). Für einen ersten Test können Sie dieses 'liblwjgl.so' in das Hauptverzeichnis Ihres Projekts einfügen und sehen, ob es funktioniert. Wenn es funktioniert, können Sie mehr über das Laden nativer Bibliotheken und den 'java.library.path' lesen. – Marco13

+0

'Setzen Sie -Djava.library.path oder -Dorg.lwjgl.librarypath auf das Verzeichnis, das die freigegebenen Bibliotheken enthält. – javac

+0

Danke, ich lese darüber. – Bort

Antwort

2

Ich kann nur von NetBeans 8 sprechen, um LWJGL 3 auszuführen, aber ich habe auch den gleichen Fehler. Das Problem, das ich gefunden habe, hatte mit den "nativen" JAR-Dateien zu tun, die bei der Einrichtung von LWJGL zunächst zur Registerkarte "Klassenpfad" hinzugefügt werden müssen. Der Grund dafür ist, dass LWJGL die nativen Jars automatisch finden kann. Dann unter die VM-Einstellungen sollten Sie es auf:

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

Nur umfassen Anführungszeichen, wenn Ihr Pfadname keine Leerzeichen enthält

-2

Wenn Sie eine Bibliothek hinzufügen möchten Sie den gesamten Ordner hinzufügen müssen und nicht einer danach wird das Problem überwinden (Entschuldigung für schlechtes Englisch). enter image description here

Verwandte Themen