LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: doev on September 14, 2015, 08:38:44

Title: How do I setup the native libraries with maven?
Post by: doev on September 14, 2015, 08:38:44
Hello,

if I use lwjgl3 in the manual way I have to set "-Djava.library.path=<dir>/lwjgl_3.0.0a/native" to run the application. How is the recommend way to set this with maven?
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 14, 2015, 09:22:07
See this sample project (https://github.com/badlogic/lwjgl3-maven-gradle), you must use:

SharedLibraryLoader.load();

Please note that, before the official release of LWJGL 3.0, a similar solution will be included in LWJGL.

edit: The above is not required with the latest nightly builds.
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 14, 2015, 09:36:55
Thx. The project takes me one step forward. Now I get "Invalid X server connection specified" and I remember this problem appears if you are working with glfw in the wrong thread. But the demoproject (your link) is not working with threads.
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 14, 2015, 09:51:03
Try the latest nightly build. Use this maven URL: https://oss.sonatype.org/content/repositories/snapshots/ and this LWJGL version: 3.0.0b-SNAPSHOT.

If that doesn't work, make sure OpenGL is working fine on your machine.
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 14, 2015, 10:07:21
3.0.0b-SNAPSHOT does not change the problem, same error. But I tested Lwjgl3Test.java with "LWJGL 3.0.0a build 48 (ZIP)" and it works well.
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 14, 2015, 10:10:58
build #3.0.0b build 9 also works fine.
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 14, 2015, 15:33:17
It sounds similar to this issue (https://github.com/LWJGL/lwjgl3/issues/39). edit: also this one (http://forum.lwjgl.org/index.php?topic=5940.0).
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 14, 2015, 19:09:22
Actually, the latest 3.0.0b-SNAPSHOT doesn't have an "Invalid X server connection specified" error. Are you sure you tested the correct build?
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 15, 2015, 08:44:55
Sorry, my fault. When I use 3.0.0b-SNAPSHOT I can't compile cause GLContext.createFromCurrent(); is not known.
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 15, 2015, 08:47:41
See the latest (http://www.lwjgl.org/guide) getting started guide: you must use GL.createCapabilities().
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 15, 2015, 09:00:29
I changed "GLContext.createFromCurrent()" to "GL.createCapabilities()" and also test the HelloWorld.java example with an additional "SharedLibraryLoader.load()". In both cases I get a NullPointer-Exception:

Exception in thread "main" java.lang.NullPointerException
   at org.lwjgl.system.Checks.checkPointer(Checks.java:80)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:278)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:230)
   at HelloWorld.loop(HelloWorld.java:93)
   at HelloWorld.run(HelloWorld.java:26)
   at HelloWorld.main(HelloWorld.java:114)

Edit:

Line 93: GL.createCapabilities();
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 15, 2015, 09:07:09
Does it help if you uninstall libgl1-mesa-dev? Also, what GPU do you have?
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 15, 2015, 09:16:55
Removing libgl1-mesa-dev which includes libqt4-opengl-dev and libglu1-mesa-dev helps. Now the examples are working.

GeForce GTS 450
346.82
Linux-x86_64
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 15, 2015, 09:32:01
If it's not too much trouble, could you install libgl1-mesa-dev again, run this code and paste the output here?

System.out.println("contextGLFW  = " + GLFWLinux.glfwGetGLXContext(window));
System.out.println("contextLWJGL = " + GLX.glXGetCurrentContext());

long glXGetCurrentDisplay = GL.getFunctionProvider().getFunctionAddress("glXGetCurrentDisplay");
if ( glXGetCurrentDisplay != NULL ) {
long displayGLFW = GLFWLinux.glfwGetX11Display();
long displayLWJGL = JNI.callP(glXGetCurrentDisplay);

System.out.println("displayGLFW  = " + displayGLFW);
System.out.println("displayLWJGL = " + displayLWJGL);
} else {
System.out.println("glXGetCurrentDisplay not found.");
}


Add it between glfwMakeContextCurrent(window) and GL.createCapabilities(). There is a good chance that simply reinstalling libgl1-mesa-dev won't reproduce the issue. If that happens, try reinstalling the Nvidia drivers, after libgl1-mesa-dev.

edit: Also, see if mesa adds a "libGL.so.1" symlink anywhere.
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 15, 2015, 09:50:23
contextGLFW  = 139802799196784
contextLWJGL = 139802799196784
displayGLFW  = 139802798297344
displayLWJGL = 0


I don't see any new symlink to libGL.so.1

There are two new links:

lrwxrwxrwx 1 root root 13 Mär 11  2015 /usr/lib/x86_64-linux-gnu/libGL.so -> mesa/libGL.so
lrwxrwxrwx 1 root root 14 Mär 11  2015 /usr/lib/x86_64-linux-gnu/mesa/libGL.so -> libGL.so.1.2.0
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 15, 2015, 10:01:05
Thanks, I might have an idea for a fix, but will have to wait for a new build.

Quote from: doev on September 15, 2015, 09:50:23There are two new links:

lrwxrwxrwx 1 root root 13 Mär 11  2015 /usr/lib/x86_64-linux-gnu/libGL.so -> mesa/libGL.so
lrwxrwxrwx 1 root root 14 Mär 11  2015 /usr/lib/x86_64-linux-gnu/mesa/libGL.so -> libGL.so.1.2.0

Those shouldn't affect LWJGL, because we load libGL.so.1 (with the .1 postfix). In theory, if you remove those symlinks manually, LWJGL will still fail. Could you confirm please?
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 15, 2015, 10:08:20
- Example is working
- Install libgl1-mesa-dev
- Example fail
- mv /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGL.so_backup
- mv /usr/lib/x86_64-linux-gnu/mesa/libGL.so /usr/lib/x86_64-linux-gnu/mesa/libGL.so_backup
- Example is working
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 15, 2015, 10:24:48
OK, that's weird and very helpful. Thanks for taking the time to test!

More info: LWJGL tries to load libGL.so.1 first, if that fails, it loads libGL.so. I can't check right now, but last time I did on an Ubuntu/Nvidia machine, libGL.so.1 was working fine and loaded the Nvidia implementation. Could you please search if libGL.so.1 is available anywhere? It must be, otherwise GLFW wouldn't work either (it tries libGL.so.1 only).
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 15, 2015, 10:51:24
/usr/lib/nvidia-346/libGL.so.1 -> libGL.so.346.82
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 -> libGL.so.1.2.0
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 15, 2015, 11:00:12
So, there indeed is a mesa symlink for libGL.so.1. Not sure if this is fixable, but I'll let you know when a new build is up to test.
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 15, 2015, 11:23:21
Ok, thx. :)
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 15, 2015, 14:26:50
The new build is up (3.0.0b #27), could you try again please?

edit: If it fails again, please add "-Dorg.lwjgl.util.Debug=true" to the command line and post the output here.
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 19, 2015, 21:52:03
Hey doev, did you have a chance to try it out?

Also, the latest build (3.0.0b #28) includes the SharedLibraryLoader and you don't have to call it explictly, the native libraries are extracted automatically (as long as the JAR that contains them is in the classpath).
Title: Re: How do I setup the native libraries with maven?
Post by: huhlig on September 21, 2015, 06:43:50
Ok, Be aware. DO NOT CALL the example SharedLibraryLoader.load() if you are using the nightly. It breaks everything.
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 22, 2015, 09:13:10
I don't know how to use a specific snapshot version. If I use "3.0.0b-SNAPSHOT" (think that is the latest) the example runs without libgl1-mesa-dev installed but not otherwise.

Exception in thread "main" java.lang.NullPointerException
   at org.lwjgl.system.Checks.checkPointer(Checks.java:80)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:278)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:230)
   at Lwjgl3Test.loop(Lwjgl3Test.java:113)
   at Lwjgl3Test.run(Lwjgl3Test.java:28)
   at Lwjgl3Test.main(Lwjgl3Test.java:135)
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 22, 2015, 09:31:24
What's the output if you run it with -Dorg.lwjgl.util.Debug=true?
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 22, 2015, 09:57:20
Cause I actually don't know a better way, I started the test with:

java -Dorg.lwjgl.util.Debug=true -cp lwjgl3-tests-1.0-SNAPSHOT-jar-with-dependencies.jar Lwjgl3Test

Lwjgl3Test
[LWJGL] Version 3.0.0b | Linux | amd64
[LWJGL] Loaded library from org.lwjgl.librarypath: liblwjgl.so
Hello LWJGL 3.0.0b!
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] Loaded native library: /tmp/lwjgldoev/d0227e9/libjemalloc.so
[LWJGL] MemoryUtil allocator: JEmallocAllocator
[LWJGL] Loaded native library: /tmp/lwjgldoev/d0227e9/libglfw.so
[LWJGL] Loaded native library: /usr/lib/x86_64-linux-gnu/libGL.so
Exception in thread "main" java.lang.NullPointerException
   at org.lwjgl.system.Checks.checkPointer(Checks.java:80)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:278)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:230)
   at Lwjgl3Test.loop(Lwjgl3Test.java:113)
   at Lwjgl3Test.run(Lwjgl3Test.java:28)
   at Lwjgl3Test.main(Lwjgl3Test.java:135)


The output if libgl1-dev is not installed:

Lwjgl3Test
[LWJGL] Version 3.0.0b | Linux | amd64
[LWJGL] Loaded library from org.lwjgl.librarypath: liblwjgl.so
Hello LWJGL 3.0.0b!
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] Loaded native library: /tmp/lwjgldoev/d0227e9/libjemalloc.so
[LWJGL] MemoryUtil allocator: JEmallocAllocator
[LWJGL] Loaded native library: /tmp/lwjgldoev/d0227e9/libglfw.so
[LWJGL] Loaded native library: libGL.so.1
[LWJGL] Failed to locate address for GL function glNamedBufferPageCommitmentARB
[LWJGL] Failed to locate address for GL function glVertexWeighthNV
[LWJGL] Failed to locate address for GL function glVertexWeighthvNV
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 22, 2015, 11:26:06
A new build is up (#33), could you try again please?
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 22, 2015, 11:36:58
Can I be sure that it is the new build if I have done a clean+build?



[LWJGL] Version 3.0.0b | Linux | amd64
[LWJGL] Loaded library from org.lwjgl.librarypath: liblwjgl.so
Hello LWJGL 3.0.0b!
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] Loaded native library: /tmp/lwjgldoev/d0227e9/libjemalloc.so
[LWJGL] MemoryUtil allocator: JEmallocAllocator
[LWJGL] Loaded native library: /tmp/lwjgldoev/d0227e9/libglfw.so
[LWJGL] Loaded native library: /usr/lib/x86_64-linux-gnu/libGL.so
Exception in thread "main" java.lang.NullPointerException
   at org.lwjgl.system.Checks.checkPointer(Checks.java:80)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:278)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:230)
   at Lwjgl3Test.loop(Lwjgl3Test.java:113)
   at Lwjgl3Test.run(Lwjgl3Test.java:28)
   at Lwjgl3Test.main(Lwjgl3Test.java:135)
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 22, 2015, 11:42:03
Based on the output, this appears to not be the latest build. I'll try to include the build number in the version string in future builds.
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 22, 2015, 11:48:04
ls -lah /home/doev/.m2/repository/org/lwjgl/lwjgl/3.0.0b-SNAPSHOT/

insgesamt 5,0M
drwxrwxr-x 2 doev doev 4,0K Sep 22 10:47 .
drwxrwxr-x 9 doev doev 4,0K Sep 22 10:58 ..
-rw-rw-r-- 1 doev doev 1,4M Sep 15 10:41 lwjgl-3.0.0b-20150914.152003-32.jar
-rw-rw-r-- 1 doev doev   40 Sep 15 10:41 lwjgl-3.0.0b-20150914.152003-32.jar.sha1
-rw-rw-r-- 1 doev doev 1019 Sep 15 10:41 lwjgl-3.0.0b-20150914.152003-32.pom
-rw-rw-r-- 1 doev doev   40 Sep 15 10:41 lwjgl-3.0.0b-20150914.152003-32.pom.sha1
-rw-rw-r-- 1 doev doev 1,8M Sep 22 10:47 lwjgl-3.0.0b-20150920.210645-38.jar
-rw-rw-r-- 1 doev doev   40 Sep 22 10:47 lwjgl-3.0.0b-20150920.210645-38.jar.sha1
-rw-rw-r-- 1 doev doev 1019 Sep 22 10:47 lwjgl-3.0.0b-20150920.210645-38.pom
-rw-rw-r-- 1 doev doev   40 Sep 22 10:47 lwjgl-3.0.0b-20150920.210645-38.pom.sha1
-rw-rw-r-- 1 doev doev 1,8M Sep 22 10:47 lwjgl-3.0.0b-SNAPSHOT.jar
-rw-rw-r-- 1 doev doev 1019 Sep 22 10:47 lwjgl-3.0.0b-SNAPSHOT.pom
-rw-rw-r-- 1 doev doev 1,2K Sep 22 10:47 maven-metadata-snapshots-repo.xml
-rw-rw-r-- 1 doev doev   40 Sep 22 10:47 maven-metadata-snapshots-repo.xml.sha1
-rw-rw-r-- 1 doev doev  211 Sep 22 10:47 _maven.repositories
-rw-rw-r-- 1 doev doev  187 Sep 22 10:47 resolver-status.properties
Title: Re: How do I setup the native libraries with maven?
Post by: doev on September 22, 2015, 11:55:35
I deleted the local repo and rebuild it. It works now.

lwjgl-3.0.0b-20150922.112323-39.jar

[LWJGL] Version 3.0.0b | Linux | amd64
[LWJGL] Loaded library from org.lwjgl.librarypath: liblwjgl.so
getVersion(): 3.0.0b
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] Loaded native library: /tmp/lwjgldoev/d0227e9/libjemalloc.so
[LWJGL] MemoryUtil allocator: JEmallocAllocator
[LWJGL] Loaded native library: /tmp/lwjgldoev/d0227e9/libglfw.so
[LWJGL] Loaded native library: libGL.so.1
[LWJGL] Failed to locate address for GL function glNamedBufferPageCommitmentARB
[LWJGL] Failed to locate address for GL function glVertexWeighthNV
[LWJGL] Failed to locate address for GL function glVertexWeighthvNV
Title: Re: How do I setup the native libraries with maven?
Post by: spasi on September 22, 2015, 12:55:21
Awesome, thanks again for testing!