Compiling/running a LWJGL program from terminal

Tags: ,

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(
    at org.lwjgl.system.Library.loadSystem(
    at org.lwjgl.system.Library.<clinit>(
    at org.lwjgl.system.MemoryUtil.<clinit>(
    at org.lwjgl.system.Pointer$Default.<clinit>(
    at org.lwjgl.system.Callback.<clinit>(
    at HelloWorld.init(
    at HelloWorld.main(

The code is identical to the guide code at, and I’m using the following commands to compile and run:

javac -cp .:lib/* 
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:

| lwjgl.jar
| lwjgl-glfw.jar
| lwjgl-opengl.jar
| macos
| | lwjgl-glfw-natives-macos.jar
| | lwjgl-natives-macos.jar
| | lwjgl-opengl-natives-macos.jar

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.


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.

Source: stackoverflow