What is best practice to call `SymbolLookup.libraryLookup()` in cross-platform way?
Daniel Lemire
daniel at lemire.me
Fri Jan 30 14:55:39 UTC 2026
I have a blog post on the topic and it worked for me:
Daniel Lemire, "A new way to call C from Java: how fast is it?," in *Daniel Lemire's blog*, January 17, 2026, https://lemire.me/blog/2026/01/17/a-new-way-to-call-c-from-java-how-fast-is-it/.
Code sample:
`System*.*loadLibrary*(*"sum"*);*
Linker linker *=* Linker*.*nativeLinker*();*
SymbolLookup lookup *=* SymbolLookup*.*loaderLookup*();*
MemorySegment sumAddress *=* lookup*.*find*(*"sum_array"*).*orElseThrow*();*`
On Fri, Jan 30, 2026, at 07:18, Lev Serebryakov wrote:
> January 29, 2026 at 5:39 PM, "Daniel Lemire" <daniel at lemire.me> wrote:
>
>
> > Maybe.,..
> >
> > System.loadLibrary("mylib");
> >
>
> As far as I can tell java.lang.foreign doesn't use `System.loadLibrary()` and one cannot be converted to another.
>
> Documentation in JDK says it is `dlopen()` for POSIX-like and `LoadLibrary()` for Windows (which is pity, as they requires very different arguments). But I cannot make it work on MacOS even with `dlopen()` rules.
>
> And I don't want to use full paths, as they are very OS-specific...
>
>
> --
> // Lev Serebryakov
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20260130/93566e60/attachment-0001.htm>
More information about the panama-dev
mailing list