I’m trying to compile and run an LWJGL project purely from the console without the use of Maven/Gradle or any IDE (for reasons). I’m running Mac OS X v10.15.4. The program seems to compile fine but upon running it, I get the following:
[LWJGL] Version: 3.2.3 build 13 [LWJGL] OS: Mac OS X v10.15.4 [LWJGL] JRE: 12 x86_64 [LWJGL] JVM: Java HotSpot(TM) 64-Bit Server VM v12+33 by Oracle Corporation [LWJGL] Loading JNI library: lwjgl [LWJGL] Module: org.lwjgl [LWJGL] macos/x64/org/lwjgl/liblwjgl.dylib not found in java.library.path=native [LWJGL] liblwjgl.dylib not found in java.library.path [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. Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to locate library: liblwjgl.dylib at org.lwjgl.system.Library.loadSystem(Library.java:162) at org.lwjgl.system.Library.loadSystem(Library.java:62) at org.lwjgl.system.Library.<clinit>(Library.java:50) at org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:97) at org.lwjgl.system.Pointer$Default.<clinit>(Pointer.java:67) at org.lwjgl.system.Callback.<clinit>(Callback.java:41) at HelloWorld.init(HelloWorld.java:37) at HelloWorld.run(HelloWorld.java:22) at HelloWorld.main(HelloWorld.java:112)
The code is identical to the guide code at https://www.lwjgl.org/guide, and I’m using the following commands to compile and run:
javac -cp .:lib/* HelloWorld.java java -cp .:lib/* -Djava.library.path=native/macos HelloWorld
I think that where I’m going wrong (and what the error message suggests) is that I’m either missing native files or they’re just setup incorrectly but for all my searching I can’t seem to find an answer. Here is my directory setup:
lib | lwjgl.jar | lwjgl-glfw.jar | lwjgl-opengl.jar native | macos | | lwjgl-glfw-natives-macos.jar | | lwjgl-natives-macos.jar | | lwjgl-opengl-natives-macos.jar HelloWorld.java HelloWorld.class
I’ve seen Building and running lwjgl program from terminal and it doesn’t seem this issue is addressed there. I’ve also searched around for liblwjgl.dylib but from what I understand, LWJGL’s SharedLibraryLoader should be handling this.
Advertisement
Answer
What seemed to fix it was putting the native files in the lib folder and then just running as follows:
java -cp .:lib/* -XstartOnFirstThread HelloWorld
note that on MacOSS -XstartOnFirstThread is necessary or the program will immediately crash.