java-native-access / java-native-access/jna
Error looking up function from current process on Linux
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.9k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
Description
JNA seems to be unable to look up functions from the current process, specifically on Linux x64, while the same code works fine on Windows x64 and macOS aarch64. The documentation says JNA should look into the current process if null is passed to Native.load.
Additional details
-
The Foreign Function & Memory API from Java 22 finds all functions and all tests succeed
-
nmseems to indicate the function is in the shared library, and isn't mangled -
The only workaround is to let JNA load the shared library by
Native.load("/path/to/libzstd.so", ZstdJna.class)
Repro code
Using the Linux x64 binary found at https://github.com/freya022/discord-zstd-java/actions/runs/18886251057
public interface ZstdJna extends Library {
ZstdJna INSTANCE = Native.load(null, ZstdJna.class);
Pointer ZSTD_createDStream();
}
public class Repro {
public static void main(String[] args) {
System.load("/path/to/libzstd.so");
ZstdJna.INSTANCE // Fine
.ZSTD_createDStream(); // Fails
}
}
Environment
Java Version: OpenJDK 25+36
JNA Version: 5.18.1 (also tested 4.4.0)
Operating System: Ubuntu 24.04 GitHub Actions runner (image details), also tested on a Kubuntu VM
C/C++ Compiler: GCC 13.3.0
Error
java.lang.UnsatisfiedLinkError: Error looking up function 'ZSTD_createDStream': /usr/lib/jvm/java-25-openjdk-amd64/bin/java: undefined symbol: ZSTD_createDStream
at com.sun.jna.Function.<init>(Function.java:255)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:618)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:594)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:580)
at com.sun.jna.Library$Handler.invoke(Library.java:248)
at jdk.proxy3/jdk.proxy3.$Proxy13.ZSTD_createDStream(Unknown Source)
at dev.freya02.discord.zstd.jna.ZstdJNATest.test_decompression(ZstdJNATest.java:36)
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
Workflow details if necessary: https://github.com/freya022/discord-zstd-java/actions/runs/18891473842
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Linux x64 case with Java 25, then trace NativeLibrary.getFunction and Function from the reported stack to inspect current-process symbol lookup. Compare Native.load(null, ZstdJna.class) with the explicit library workaround and the Java Foreign Function & Memory API. Done means the reported ZSTD_createDStream lookup succeeds without explicitly loading the shared library.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, linux
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100