Re: How to create the DLL files JNA is using in its source code

254 views
Skip to first unread message

Matthias Bläsing

unread,
Oct 14, 2023, 6:52:56 AM10/14/23
to jna-...@googlegroups.com

Hi,

Am Samstag, dem 14.10.2023 um 00:06 -0700 schrieb Valentin-Ionut Stanciu:

That being said, I downloaded the source code for JNA (from GitHub) and added into the project (I'm using Eclipse + Adoptium), but beside the source code, I didn't expect that I would need some DLL files also (I'm getting java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/win32-x86-64/jnidispatch.dll) not found in resource path). So, can someone help me create the DLL files that JNA is using with some steps or a link to how to do it? Or is it fine to extract them from the JAR files and they will work the same without problems? I'm asking as I did found this DLL file inside win32-x86-64.jar.

The game will only be available on Windows x64, and everything that I'm doing is for that platform only.

JNA uses libffi to invoke native functions. jnidispatch is the glue layer between the java part of JNA and libffi. Calling into native without external help will be possible once project panama is fully integrated into the JDK.

The question I would raise is: Why compile from source in the first place? JNA distributes binaries to maven central and these include the native parts for several platforms, including windows x64/x86-64/amd64.

The java and native parts of JNA are tightly coupled. This is also enforced by version checks when loading the glue library. This is what you are seeing in your second message:

There is an incompatible JNA native library installed on this system
Expected: TEMPLATE
Found:    7.0.0

The JNA build system modifies `src/com/sun/jna/Version.java` before compiling it. The logic can be found in https://github.com/java-native-access/jna/blob/237206727cab3cdfd0285ed57035ab3b64179ed4/build.xml#L400-L407.

If you want to ship the native DLL outside the JAR, you can set the `jna.boot.library.path` system property and point that to directory where you place the jnidispatch.dll.

HTH

Matthias

L Will Ahonen

unread,
Oct 18, 2023, 5:26:42 AM10/18/23
to Java Native Access
Hi,

I wrote this guide for IntelliJ Idea, but the same applies for Eclipse et al. There's an ant target that builds you a jar that you can include in your IDE of choice and get hacking on the java bits without having to constantly rebuild the whole jar.

https://github.com/java-native-access/jna/blob/master/www/DevelopInIDE.md

Cheers,
Will

Reply all
Reply to author
Forward
0 new messages