Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (854)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED]Lwjgl Error: Failed to load the native library: lwjgl  (Read 17960 times)
0 Members and 1 Guest are viewing this topic.
Offline gzuzboey
« Posted 2014-12-19 16:49:24 »

Hello jgo! Today i have been using lwjgl 3, and I have succesfully managed to create a glfw window! The window runs fine with no errors on Eclipse, but when I export it into runnable jar file and try opening it on my Desktop, i get the following error:

1  
2  
3  
4  
5  
6  
7  
8  
9  
Caused by: java.lang.UnsatisfiedLinkError: Failed to load the native library: lwjgl

        at org.lwjgl.LWJGLUtil.loadLibrarySystem(LWJGLUtil.java:329)
        at org.lwjgl.Sys$1.run(Sys.java:36)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.lwjgl.Sys.<clinit>(Sys.java:33)
        at core.Display.<init>(Display.java:36)
        at core.Main.main(Main.java:6)
        ... 5 more


Display.java:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
public class Display {
   
   /** The window handle */
   private long wHandle;
   
   // All event callbacks
   GLFWErrorCallback         errorCalls;
   GLFWKeyCallback         keyCalls;
   GLFWCursorPosCallback    cpCalls;
   GLFWMouseButtonCallback mbCalls;
   
   int width, height;
   String title;
   
   Game game;

   public Display(int width, int height, String title, Game game) {
      this.width = width;
      this.height = height;
      this.title = title;
      this.game = game;
     
      System.out.println("Hello Lwjgl " + Sys.getVersion());
     
      try {
         init();
         loop();
         
         // Dispose of game and resources
         if(game != null)
            game.dispose();
         
         glfwDestroyWindow(wHandle);
         
         // Release all callbacks
         if(keyCalls != null)
            keyCalls.release();
         
         if(cpCalls != null)
            cpCalls.release();
         
         if(mbCalls != null)
            mbCalls.release();
      } finally {
         glfwTerminate();
         errorCalls.release();
      }
   }
   
   private void init() {
      glfwSetErrorCallback(errorCalls = errorCallbackPrint(System.err)); // This will print any lwjgl errors to System.err
      if(glfwInit() != GL_TRUE) {
         throw new IllegalStateException("GLFW cant init!");
      }
     
      // Config window
      glfwDefaultWindowHints();
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
      glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
      glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
     
      /** Create window */
      wHandle = glfwCreateWindow(width, height, title, NULL, NULL);
      if(wHandle == NULL) {
         throw new IllegalStateException("Unable to create window, check if have a Opengl version of 3.3 or higher.");
      }
     
      // Set up key callback
      glfwSetKeyCallback(wHandle, keyCalls = new GLFWKeyCallback() {
         @Override
         public void invoke(long window, int key, int scancode, int action, int mods) {
            if(key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
               glfwSetWindowShouldClose(wHandle, GL_TRUE);
         }
      });
     
      // Get video mode of moniter
      ByteBuffer vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
     
      // Center window
      glfwSetWindowPos(wHandle, (GLFWvidmode.width(vidMode) - width) / 2,
                             (GLFWvidmode.height(vidMode) - height) / 2);
     
      // Make the Opengl context current in thread
      glfwMakeContextCurrent(wHandle);
     
      // Enable v-sync
      glfwSwapInterval(1);
     
      // Finally ready to show window
      glfwShowWindow(wHandle);
   }
   
   private void loop() {
      // Allow us to use Opengl functions
      GLContext.createFromCurrent();
     
      // Enable blending and alpha transparency for sprites
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glViewport(0, 0, width, height); // Sets viewport
     
      game.start();
     
      // Game Loop
      while(glfwWindowShouldClose(wHandle) == GL_FALSE) {
         glClearColor(0, 0, 0, 1);
         glClear(GL_COLOR_BUFFER_BIT);
         
         game.render();
         game.update();
         
         glfwSwapBuffers(wHandle);
         glfwPollEvents();
      }
   }
}


Main.java:
1  
2  
3  
4  
5  
6  
public class Main {

   public static void main(String[] args) {
      new Display(800, 600, "Lwjgl Test!", new Game());
   }
}


Help!

YA BOI
Offline kpars
« Reply #1 - Posted 2014-12-19 16:53:36 »

It can't find the natives, and you aren't supposed to export it as a runnable JAR.

Export it as a normal JAR, then use JarSplice to add the natives.

Add the JAR you exported from Eclipse, add all of the Win/Mac/Linux natives, then specify your main class and export as a fat JAR.

- Jev
Offline SilverTiger

JGO Coder


Medals: 41
Exp: 3 years


がんばってください!


« Reply #2 - Posted 2014-12-19 17:09:13 »

When you get that error, then you haven't set the
org.lwjgl.librarypath
correctly.
You could copy the native folder to the folder that contains the jar. Then in your main method do this:

1  
2  
3  
4  
5  
if (System.getProperty("org.lwjgl.librarypath") == null) {
    Path path = Paths.get("native");
    String librarypath = path.toAbsolutePath().toString();
    System.setProperty("org.lwjgl.librarypath", librarypath);
}


Does this work for you? Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gzuzboey
« Reply #3 - Posted 2014-12-19 17:18:58 »

@SilverTiger Nope I still get same error Sad

@kpars Now I get this error:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Exception in thread "main" java.lang.NoClassDefFoundError: core/Display
        at core.Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: core.Display
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 1 more

YA BOI
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 123
Projects: 15


★★★★★


« Reply #4 - Posted 2014-12-19 17:35:51 »

Looking at the code you posted there doesn't seem to be any declaration of it being the core package which could be why you are getting that error.

Also one cool thing with LWJGL3 is that you do not need to point to the exact folder containing the system specific natives (in org.lwjgl.librarypath or java.library.path), you can just point to the LWJGL natives folder and it will automatically pick up the relevant natives from the linux, window, mac sub folders. Pretty useful when using the same workspace across different platforms as you do not need to change the native path once set.

@SilverTiger should also reduce your code to
1  
2  
3  
4  
5  
if (System.getProperty("org.lwjgl.librarypath") == null) {
    Path path = Paths.get("native");
    String librarypath = path.toAbsolutePath().toString();
    System.setProperty("org.lwjgl.librarypath", librarypath);
}
Offline gzuzboey
« Reply #5 - Posted 2014-12-19 17:44:49 »

Looking at the code you posted there doesn't seem to be any declaration of it being the core package which could be why you are getting that error.

Thats the package its in:


Quote
Also one cool thing with LWJGL3 is that you do not need to point to the exact folder containing the system specific natives (in org.lwjgl.librarypath or java.library.path), you can just point to the LWJGL natives folder and it will automatically pick up the relevant natives from the linux, window, mac sub folders. Pretty useful when using the same workspace across different platforms as you do not need to change the native path once set.

I did that and I still get the same error Cry

YA BOI
Offline gzuzboey
« Reply #6 - Posted 2014-12-19 19:11:45 »

 Shocked After a long time, I have finally figured out how to export a runnable lwjgl 3.0 jar file(Pretty Amazing):

Steps for anyone with my problem(Eclipse Only):


1. In eclipse, right click your project and click export

2. Choose runnable jar file and click "Copy required libraries into a sub-folder next to the generated jar", and specify the path of your jar

3. click finish

4. Download jarsplice and open it

5. Click the ADD JARS tab, and click Add Jar(s)

6.Then go to the path of your jar and folder, and open up your folder and add all the jars in it, then add the jar that was exported

7. Then click the ADD NATIVES tab, and click Add Native(s)

8. Go to the path where you extracted lwjgl and go to the natives folder

9. Locate the folder of your os and inside locate the folder of acrhitecture(eg. x86 or x64), and add all the dlls in it

10. Then click the MAIN CLASS tab, and type in your main class(eg. "gzuzboey.game.main")

11. Click the CREATE FAT JAR tab and specify the path you where you want your jar to be at

12. Your Done!
 


I hope this helps anyone, it sure did help me Grin

YA BOI
Offline gouessej
« Reply #7 - Posted 2014-12-19 21:35:35 »

You don't need jarsplice to create a runnable JAR, there are several tools with a better maintenance to do that, you can even use a simple build tool (for example Ant).

Julien Gouesse | Personal blog | Website | Jogamp
Offline gzuzboey
« Reply #8 - Posted 2014-12-19 23:20:08 »

You don't need jarsplice to create a runnable JAR

But it works...

Quote
there are several tools with a better maintenance to do that, you can even use a simple build tool (for example Ant).

It honestly doesn't matter, you can get it working either way Tongue

YA BOI
Offline gouessej
« Reply #9 - Posted 2015-01-08 16:11:50 »

Some JarSplice bugs have been unfixed for about 4 years:
http://stackoverflow.com/questions/10998264/command-line-parameters-with-jarsplice

It honestly doesn't matter, you can get it working either way Tongue
It matters as if you're blocked by one of its bugs, you'll have to do some reverse engineering on it and fix it by yourself which would be probably a lot more time consuming than using a build tool like Ant.

Julien Gouesse | Personal blog | Website | Jogamp
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gzuzboey
« Reply #10 - Posted 2015-01-08 18:13:42 »

Quote
Some JarSplice bugs have been unfixed for about 4 years:
http://stackoverflow.com/questions/10998264/command-line-parameters-with-jarsplice

I didnt even know JarSplice had bugs Pointing

Quote
It matters as if you're blocked by one of its bugs, you'll have to do some reverse engineering on it and fix it by yourself which would be probably a lot more time consuming than using a build tool like Ant.

While a build tool like Ant might be easier, I was able to use JarSplice without any problems and therefore, I will probably continue to use it  Tongue

Btw, I think Ill have a look at Ant Grin

YA BOI
Offline minigame

Senior Devvie


Medals: 14
Projects: 1


LWJGLException


« Reply #11 - Posted 2015-01-08 19:06:14 »

I've used this little function in my games for a while. Make sure it's the first thing called in your main method. Example:

public static void main(String[] args) {
    loadNatives("path_here");
    // then start your app here
}

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
        // declare this variable
   private final static String platform = System.getProperty("os.name").toLowerCase();


   /**
    * Loads the native library from the given path, based on the local machine's operating system.
    * This MUST BE called before instancing the
    * @param pathTo The path leading to the /native/ folder (Do not include /native/ in this path!)
    */

   public static void loadNatives(String pathTo) {
      System.out.println("Machine is running: " + platform);
      if (platform.indexOf("win") >= 0) {
         System.setProperty("org.lwjgl.librarypath", new File(pathTo + "native/windows/").getAbsolutePath());
      } else if (platform.indexOf("mac") >= 0) {
         System.setProperty("org.lwjgl.librarypath", new File(pathTo + "native/macosx/").getAbsolutePath());
      } else if ((platform.indexOf("nix") >= 0 || platform.indexOf("nux") >= 0 || platform.indexOf("aix") > 0)) {
         System.setProperty("org.lwjgl.librarypath", new File(pathTo + "native/linux/").getAbsolutePath());
      } else if (platform.indexOf("sunos") >= 0) {
         System.setProperty("org.lwjgl.librarypath", new File(pathTo + "native/solaris/").getAbsolutePath());
      }
   }

while (!deadFromWork) {
    if (hasItem("Dry Erase Board")) {
        chanceOfSuccess++;// Based on a true story..
    }
}
Offline CopyableCougar4
« Reply #12 - Posted 2015-01-09 00:21:22 »

You can also use
LWJGLUtil.getPlatform()
to get an emum constant for the OS. Also, as of LWJGL 3, you need to specify a folder by 32bit vs 64bit.

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Spasi
« Reply #13 - Posted 2015-01-09 08:20:07 »

Also, as of LWJGL 3, you need to specify a folder by 32bit vs 64bit.

That was a temporary limitation, you now only have to specify the base folder. The OS and CPU architecture are resolved automatically.
Offline gouessej
« Reply #14 - Posted 2015-01-09 09:11:17 »

Also, as of LWJGL 3, you need to specify a folder by 32bit vs 64bit.

That was a temporary limitation, you now only have to specify the base folder. The OS and CPU architecture are resolved automatically.
Which architecture can be resolved automatically? Do you talk only about the "bitness"?

Julien Gouesse | Personal blog | Website | Jogamp
Offline Spasi
« Reply #15 - Posted 2015-01-09 09:42:30 »

Which architecture can be resolved automatically? Do you talk only about the "bitness"?

Whether to use x86 or x64 binaries.
Offline MrPizzaCake

Senior Devvie


Medals: 8
Exp: 3 years


Hello, another wonderful human being :)


« Reply #16 - Posted 2015-01-09 14:37:26 »

For the architecture, does LWJGL determine the architecture of the system (using native code or some secret Java trickery) or JVM (with System.getProperty("os.arch))? I haven't tested it, but I'm pretty sure that if it determined the arch. from the JVM, and someone used a x86 JVM on x64 system, it shouldn't work, because it uses wrong natives on the machine.

How am I? Tough question, since emotions are confusing as heck Tongue
Offline Spasi
« Reply #17 - Posted 2015-01-09 15:53:53 »

I'm pretty sure that if it determined the arch. from the JVM, and someone used a x86 JVM on x64 system, it shouldn't work, because it uses wrong natives on the machine.

A x86 JVM on a x64 machine requires x86 binaries.
Offline MrPizzaCake

Senior Devvie


Medals: 8
Exp: 3 years


Hello, another wonderful human being :)


« Reply #18 - Posted 2015-01-09 20:00:24 »

A x86 JVM on a x64 machine requires x86 binaries.
Oh, okay. As I said, I wasn't completely sure, I just thought it'd need x64 natives on x64 machines no matter the JVM, due to graphics card and stuff. Anyway, thanks.

How am I? Tough question, since emotions are confusing as heck Tongue
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1253 views)
2018-06-10 19:43:48

EgonOlsen (1122 views)
2018-06-10 19:43:44

EgonOlsen (860 views)
2018-06-10 19:43:20

DesertCoockie (1269 views)
2018-05-13 18:23:11

nelsongames (1103 views)
2018-04-24 18:15:36

nelsongames (1333 views)
2018-04-24 18:14:32

ivj94 (2072 views)
2018-03-24 14:47:39

ivj94 (1225 views)
2018-03-24 14:46:31

ivj94 (2166 views)
2018-03-24 14:43:53

Solater (790 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!