我开始学习如何使用LWJGL。我看了Youtube并复制了几行代码。当我编译它时,它工作,但当我试图运行它时,它说:
[LWJGL] Failed to load a library. Possible solutions:
a) Add the directory that contains the shared library to -Djava.library.path or -Dorg.lwjgl.librarypath.
b) Add the JAR that contains the shared library to the classpath.
[LWJGL] Enable debug mode with -Dorg.lwjgl.util.Debug=true for better diagnostics.
[LWJGL] Enable the SharedLibraryLoader debug mode with -Dorg.lwjgl.util.DebugLoader=true for better diagnostics.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to locate library: liblwjgl32.so
at org.lwjgl.system.Library.loadSystem(Library.java:146)
at org.lwjgl.system.Library.loadSystem(Library.java:66)
at org.lwjgl.system.Library.<clinit>(Library.java:49)
at org.lwjgl.system.MemoryAccessJNI.<clinit>(MemoryAccessJNI.java:13)
at org.lwjgl.system.Pointer.<clinit>(Pointer.java:22)
at org.lwjgl.system.Platform.mapLibraryNameBundled(Platform.java:80)
at org.lwjgl.glfw.GLFW.<clinit>(GLFW.java:602)
at Main.main(Main.java:6)
这是我从Youtube复制的代码:
import static org.lwjgl.glfw.GLFW.*;
import org.lwjgl.glfw.GLFWVidMode;
public class Main {
public static void main (String[] args) {
if (!glfwInit()) {
throw new IllegalStateException("Failed to initialize GLFW!");
}
glfwWindowHint(GLFW_VISIBLE,GLFW_FALSE);
long window = glfwCreateWindow(640, 480, "My Program", 0, 0);
if (window == 0) {
throw new IllegalStateException("Failed to create window!");
}
GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (videoMode.width() - 640) / 2, (videoMode.height() - 480) / 2);
glfwShowWindow(window);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
}
}
答案 0 :(得分:0)
这是一个错误,因为您没有在类路径中拥有所有依赖项。您需要添加LWJGL
jar及其所有依赖项。
在克服此错误(UnsatisfiedLinkError
)之后再试一次。