<!DOCTYPE html><html><head><title></title></head><body><div>I have a blog post on the topic and it worked for me:<br></div><div><br></div><div><span class="color" style="color:rgb(34, 49, 63);"><span class="highlight" style="background-color:rgb(247, 247, 247);"></span>Daniel Lemire, "A new way to call C from Java: how fast is it?," in </span><i>Daniel Lemire's blog</i><span class="color" style="color:rgb(34, 49, 63);"><span class="highlight" style="background-color:rgb(247, 247, 247);"></span>, January 17, 2026, </span><a href="https://lemire.me/blog/2026/01/17/a-new-way-to-call-c-from-java-how-fast-is-it/">https://lemire.me/blog/2026/01/17/a-new-way-to-call-c-from-java-how-fast-is-it/</a><span class="color" style="color:rgb(34, 49, 63);"><span class="highlight" style="background-color:rgb(247, 247, 247);"></span>.</span><br></div><div><br></div><div>Code sample: </div><div><br></div><pre style="border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);border-image-source:none;border-image-slice:100%;border-image-width:1;border-image-outset:0;border-image-repeat:stretch;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;background-position-x:0%;background-position-y:0%;background-size:auto;background-repeat:repeat;background-attachment:scroll;background-origin:padding-box;background-clip:border-box;background-color:rgb(246, 246, 246);font-family:menlo, consolas, monospace;font-size:90%;margin-top:7px;margin-right:0px;margin-bottom:7px;margin-left:0px;padding-top:7px;padding-right:10px;padding-bottom:7px;padding-left:10px;white-space-collapse:preserve;text-wrap-mode:wrap;overflow-wrap:break-word;"><code style="border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);border-image-source:none;border-image-slice:100%;border-image-width:1;border-image-outset:0;border-image-repeat:stretch;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;background-position-x:0%;background-position-y:0%;background-size:auto;background-repeat:repeat;background-attachment:scroll;background-origin:padding-box;background-clip:border-box;background-color:rgb(246, 246, 246);font-family:menlo, consolas, monospace;font-size:90%;padding-top:1px;padding-right:3px;padding-bottom:1px;padding-left:3px;"><span class="color" style="color:rgb(0, 0, 0);">System</span><span class="color" style="color:rgb(0, 0, 0);"><b>.</b></span><span class="color" style="color:rgb(196, 160, 0);">loadLibrary</span><span class="color" style="color:rgb(0, 0, 0);"><b>(</b></span><span class="color" style="color:rgb(78, 154, 6);">"sum"</span><span class="color" style="color:rgb(0, 0, 0);"><b>);</b></span>
<span class="color" style="color:rgb(0, 0, 0);">Linker</span> <span class="color" style="color:rgb(0, 0, 0);">linker</span> <span class="color" style="color:rgb(206, 92, 0);"><b>=</b></span> <span class="color" style="color:rgb(0, 0, 0);">Linker</span><span class="color" style="color:rgb(0, 0, 0);"><b>.</b></span><span class="color" style="color:rgb(196, 160, 0);">nativeLinker</span><span class="color" style="color:rgb(0, 0, 0);"><b>();</b></span>
<span class="color" style="color:rgb(0, 0, 0);">SymbolLookup</span> <span class="color" style="color:rgb(0, 0, 0);">lookup</span> <span class="color" style="color:rgb(206, 92, 0);"><b>=</b></span> <span class="color" style="color:rgb(0, 0, 0);">SymbolLookup</span><span class="color" style="color:rgb(0, 0, 0);"><b>.</b></span><span class="color" style="color:rgb(196, 160, 0);">loaderLookup</span><span class="color" style="color:rgb(0, 0, 0);"><b>();</b></span>
<span class="color" style="color:rgb(0, 0, 0);">MemorySegment</span> <span class="color" style="color:rgb(0, 0, 0);">sumAddress</span> <span class="color" style="color:rgb(206, 92, 0);"><b>=</b></span> <span class="color" style="color:rgb(0, 0, 0);">lookup</span><span class="color" style="color:rgb(0, 0, 0);"><b>.</b></span><span class="color" style="color:rgb(196, 160, 0);">find</span><span class="color" style="color:rgb(0, 0, 0);"><b>(</b></span><span class="color" style="color:rgb(78, 154, 6);">"sum_array"</span><span class="color" style="color:rgb(0, 0, 0);"><b>).</b></span><span class="color" style="color:rgb(196, 160, 0);">orElseThrow</span><span class="color" style="color:rgb(0, 0, 0);"><b>();</b></span></code></pre><div><br></div><div><br></div><div>On Fri, Jan 30, 2026, at 07:18, Lev Serebryakov wrote:</div><blockquote type="cite" id="qt" style=""><div>January 29, 2026 at 5:39 PM, "Daniel Lemire" <<a href="mailto:daniel@lemire.me">daniel@lemire.me</a>> wrote:</div><div><br></div><div><br></div><div>> Maybe.,..</div><div>> </div><div>> <a href="http://System.loadLibrary">System.loadLibrary</a>("mylib");</div><div>> </div><div><br></div><div>As far as I can tell <a href="http://java.lang.foreign">java.lang.foreign</a> doesn't use `<a href="http://System.loadLibrary">System.loadLibrary</a>()` and one cannot be converted to another.</div><div><br></div><div>  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.</div><div><br></div><div>  And I don't want to use full paths, as they are very OS-specific...</div><div><br></div><div><br></div><div>-- </div><div>// Lev Serebryakov</div><div><br></div></blockquote><div><br></div></body></html>