Getting 'java.lang.UnsatisfiedLinkError': no lwjgl in java.library.path

90,403

Solution 1

You don't have the natives set up in your LWJGL application.

Here's how to do it:

  1. Go to your LWJGL folder that contains the folders named "jar", "res", "doc", and "native". You need to go into Eclipse (assuming you use eclipse), open your project in the Project Explorer on the left side of your screen.
  2. Right click on the "JRE System Library" of your project, and click "Build Path" -> "Configure Build Path".
  3. Include the LWJGL native libraries to your project in the Build Path Configurer by clicking the "Native library location" which can be seen in the JRE System Library dropdown menu.
  4. Click on "Edit...", which will be the only button clickable in that general area.
  5. A file explorer will pop up. Navigate to the location of your LWJGL native folder (The location should be something like "C:\Users\YOURUSERNAMEHERE\Desktop\Java\eclipse\lwjgl-2.9.0\native" if you are using Windows) and include the folder named [Your OS here].

Hope this helped :)

Solution 2

I was following the tutorial here, and it looks like I didn't do the Adding the natives step, or I did it incorrectly.

Follow the instructions in that link and the problem should be resolved:

This is done by clicking the little arrow next to the lwjgl.jar file to show the drop down list. Double click 'Native library location' and select the folder that contains the native files for your operating system and clicking OK. These are located in the natives folder include in the LWJGL download bundle (e.g. On Windows you'd point to the natives\windows folder which contains the *.dll files, On Mac you'd point to the natives/macosx folder and on Linux you'd point to the natives/linux folder).

Solution 3

If you try tu run this code:

public static void main(String... args){
    System.out.println(System.getProperty("java.library.path"));
}

you should get output like this: /Users/yourName/.sdkman/candidates/java/8.0.252.j9-adpt/jre/lib/compressedrefs:/Users/yourName/.sdkman/candidates/java/8.0.252.j9-adpt/jre/lib:/usr/lib

So, you just need to download LWJGL libraries and copy files located at "...native/yourOSname" to one of this folders

That works to me fine!

Share:
90,403

Related videos on Youtube

Nic
Author by

Nic

Still angry at SX for banning a mod over asking how to correctly gender someone, but at least they're making steps in the right direction now.

Updated on February 11, 2022

Comments

  • Nic
    Nic over 2 years

    Note this is different from this question because it does not deal with linking because it's not asking how to link it via the CLI, but the GUI in Eclipse.

    I have been trying to write a simple program using LWJGL. When I add the library to Eclipse (Kepler 4.3.1 on Windows 7 64bit) and write a program, it does not show red squigglies under the the things which use LWJGL. However, trying to run it gives me the following stacktrace:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at org.lwjgl.Sys$1.run(Sys.java:73)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
        at org.lwjgl.Sys.loadLibrary(Sys.java:95)
        at org.lwjgl.Sys.<clinit>(Sys.java:112)
        at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
        at DisplayExample.start(DisplayExample.java:8)
        at DisplayExample.main(DisplayExample.java:23)
    

    (Yes, that is the example they give first, but I wanted to run it to make sure everything was installled properly)

    My question is, how do I fix this error? Note that, even when running in Eclipse, it still fails. If I run something else which does not use LWJGL it works, too. I just downloaded it from the internet - it only had one version, so I assume it was the correct one. From what I can see, none of the other question askers have the same error as me - but if you could point me to informative questions that would be helpful too.

    • S.R.I
      S.R.I over 10 years
      I assume you have looked at this SO Question?
    • Nic
      Nic over 10 years
      @S.R.I I figured it out myself just a few moments ago... I feel fairly stupid for not looking at the tutorial. Thanks, though
    • S.R.I
      S.R.I over 10 years
      No worries, we all have our stupid moments. :-)
  • Nic
    Nic over 10 years
    Accepting your answer instead of mine because yours is more informative.
  • BrainSlugs83
    BrainSlugs83 over 9 years
    That fixed the issue for me. I was trying to compile Minecraft from Eclipse. -- It had it's own lwjgl library/natives included, but that did not work -- it looks like it didn't have the DirectX dlls. -- I just downloaded the latest one and unpacked it to my c:\Program Files\java\jre7\lib\lwjgl-2.9.1 and followed the above instructions, and it worked great. Thank you!
  • scottysseus
    scottysseus over 7 years
    For IntelliJ users, right click 'lwjgl.jar' under 'External Libraries', click 'Open Library Settings' -> 'Modules'. Select 'lwjgl.jar', click the 'Edit' button on the right pane [it looks like a pencil]. Click the 'Add' button in the new window, and select the package for your OS in the 'native' folder/directory of your 'lwjgl' installation location (e.g. <root>/native/windows/lwjgl.dll).