2016-08-13 42 views
3

一直在嘗試在linux上使用'lwjgl',並且在從終端運行我的編譯代碼時遇到問題。我使用LWJGL 3.LWJGL:未能加載庫

的穩定版本我下載從網站上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; 
     } 
    } 
} 

}

你們可以給任何幫助將是非常讚賞。

謝謝。

+1

一般來說,錯誤是非常常見的,您的描述不是很具體。正如消息所示:它找不到本地庫。請注意*除了JAR之外,您還需要'liblwjgl.so'(它包含在您從網站下載的ZIP包中)。對於第一次測試,您可以將這個'liblwjgl.so'放到您項目的主目錄中,並查看它是否有效。如果有效,你可以閱讀更多關於本地庫加載和java.library.path的信息。 – Marco13

+0

'將-Djava.library.path或-Dorg.lwjgl.librarypath設置爲包含共享庫的目錄。' – javac

+0

謝謝,我將閱讀有關此信息。 – Bort

回答

2

我只能說使用NetBeans 8來運行LWJGL 3,但我也遇到了同樣的錯誤。我發現的問題與最初設置LWJGL時需要添加到「classpath」選項卡中的「本機」jar文件有關。其原因是它使LWJGL能夠自動查找原生罐。然後在你的虛擬機的設置,你會想將它設置爲:

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

僅包括引號如果路徑名稱包含空格

-2

當你想添加你必須添加整個文件夾圖書館和沒有一個能夠解決問題的人(對於英語不好)。 enter image description here