What is best practice to call `SymbolLookup.libraryLookup()` in cross-platform way?

Glavo zjx001202 at gmail.com
Fri Jan 30 10:11:27 UTC 2026


Hi Lev,

Others have already answered your question. However, as a supplement: if
you want to get the complete filename of a library in a cross-platform way,
you can use System.mapLibraryName(String).

For example, when you call System.mapLibraryName("a"), you will get:

   - Windows: a.dll
   - Linux: liba.so
   - macOS: liba.dylib

Glavo

On Thu, Jan 29, 2026 at 11:14 PM Lev Serebryakov <lev at blacklion.dev> wrote:

> Hello!
>
>   I wonder, is there best practices for `SymbolLookup.libraryLookup()`?
>
>   I mean, in POSIX-like systems it look in system directories and I can
> simply pass `"libname"` as argument. But on Windows it doesn't work even
> with `-Djava.library.path` which points do directory with `libname.dll`,
> looks like I need ".dll" to name.
>
>   Check for OS via property "os.name" looks like bad solution: maybe, on
> other systems, which I'm not ware about, I need add other extension, and my
> code which check will fails!
>
>   And I cannot understand what should I pass in MacOS. I've tried "name",
> "libname", "libname.dylib" — nothing works. Library file is "libname.dylib"
> in directory passed as `-Djava.library.path".
>
>   Is here better and future-proof way?
>
>   I can copy code from JNA, but I don't like it very much, to be honest.
>
> Thnak you.
>
> --
> // Lev Serebryakov
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20260130/127c1f99/attachment.htm>


More information about the panama-dev mailing list