Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (857)
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  
  [LWJGL] Library.loadNative does not work, System.load does for custom lib  (Read 964 times)
0 Members and 1 Guest are viewing this topic.
Online ClaasJG

JGO Coder

Medals: 43

« Posted 2018-07-01 14:06:42 »

Good day everyone,

I have a small project which uses jni and till now I had the dynamic library in an fixed folder for testing.
Now I am trying to bundle it within the jar and because I am using Lwjgl anyway for convenience I wanted to use the loading facilities from org.lwjgl.system.Library.

This does not work for me I received an java.lang.UnsatisfiedLinkError: test.Test.add(II)I Exception.
Lwjgl3 provides the following log for a lib not packed (And a similar for one with a packed lib):
[LWJGL] Version: 3.1.6 build 14
[LWJGL]     OS: Windows 10 v10.0
[LWJGL]    JRE: 10.0.1 amd64
[LWJGL]    JVM: Java HotSpot(TM) 64-Bit Server VM v10.0.1+10 by "Oracle Corporation"
[LWJGL] Loading library (system): lwjgl
[LWJGL]    Found at: C:\Users\CJG\AppData\Local\Temp\lwjglCJG\3.1.6-build-14\lwjgl.dll
[LWJGL]    Loaded from org.lwjgl.librarypath: C:\Users\CJG\AppData\Local\Temp\lwjglCJG\3.1.6-build-14\lwjgl.dll
[LWJGL] Loading library: C:\Users\CJG\eclipse-workspace\test\build\lib\main\release\test.dll
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL]    Success

When I use System#load or System#loadLibrary (Even when using an absolute path to the file lwjgl3 extracted) everything works as expected.

When I use System#load after calling Library#loadNative the Exception stays the same.

Do I have some misconception about Library? Anyway, thanks to everyone who can help me (or can not help me but took the time to consider if he possibly could Wink )

Have a nice weekend

My english has to be tweaked. Please show me my mistakes.
Offline KaiHH

JGO Kernel

Medals: 658

« Reply #1 - Posted 2018-07-01 15:09:33 »

org.lwjgl.system.Library.loadNative() is not meant to load JNI libraries that the JVM can then resolve native methods from.
Instead, org.lwjgl.system.Library is meant to load the raw shared library using OS-specific API calls which the JVM does not know anything about in order to manually resolve function pointer addresses via SharedLibrary/FunctionProvider.getFunctionAddress().
In order to load a JNI library (and have the JVM know about that so that it can resolve native methods to JNI functions), you have to use System.load(), System.loadLibrary(), Runtime.load() or Runtime.loadLibrary().
Online ClaasJG

JGO Coder

Medals: 43

« Reply #2 - Posted 2018-07-01 15:27:00 »

Ok, thanks for the explanation Smiley


My english has to be tweaked. Please show me my mistakes.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spasi
« Reply #3 - Posted 2018-07-01 19:29:53 »

The org.lwjgl.system.Library class supports two library loading methods:

SharedLibrary loadNative()
, used for standard native libraries (e.g. GLFW or the OpenGL/Vulkan ICDs).
void loadSystem()
, used for JNI libraries.

Both support the same mechanism for discovering shared libraries from paths (java.library.path / org.lwjgl.librarypath / system paths) or JAR files (automatically extracted to a temp or user-specified folder). Switching from loadNative() to loadSystem() should fix the issue.
Online ClaasJG

JGO Coder

Medals: 43

« Reply #4 - Posted 2018-07-01 20:32:07 »

Hui, I am to dumb to browse documentation it seems  persecutioncomplex

It works like a charm now and replaces my hackish code.


My english has to be tweaked. Please show me my mistakes.
Pages: [1]
  ignore  |  Print  

hadezbladez (1143 views)
2018-11-16 13:46:03

hadezbladez (514 views)
2018-11-16 13:41:33

hadezbladez (1176 views)
2018-11-16 13:35:35

hadezbladez (261 views)
2018-11-16 13:32:03

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

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

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

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

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

nelsongames (2803 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

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 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‑
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!