Hello, I'm trying to use a native lib with `jvmArg...
# compose-desktop
j
Hello, I'm trying to use a native lib with
jvmArgs += "-Djava.library.path=%PATH%;C:\path\to\mylib"
in Windows, but when I load it with
System.loadLibrary(libname)
, I get an UnsatisfiedLinkError. I'm trying to build an executable file with the
createDistributable
gradle task from this Compose Multiplatform tutorial. What I don't understand is why
System.getProperty("java.library.path")
results in
%PATH%;C:pathtomylib
, without backslashes and without
%PATH%
being actually resolved. I want the property to be the content of PATH together with the path to my lib, i.e. something like
C:\path\one;C:\path\two;C:\path\to\mylib
. I found out that surrounding the final path with quotes (
"-Djava.library.path="\"%PATH%;C:\path\to\mylib\""
) brings back backslashes, but the issue with
%PATH%
persists. The next attempt was
"-Djava.library.path="\"${System.getenv("PATH")};C:\path\to\mylib\""
, but then the
createDistributable
task itself threw a TaskExecutionException, with the error log being
Error: Invalid Option: [Files\Git\cmd;C:\Users\tempj\AppData\Local\Microsoft\WindowsApps;;C:\path\to\mylib']
(I suspect that the single quote at the end might be the culprit, but I myself didn't insert it...).
Also, the whole thing works when I simply modify the PATH variable to include
C:\path\to\mylib
, so that's why I'm attempting to set the library path to PATH + the path to the lib.
e
double up the backslashes, they're being treated as escapes
m
It is not a good idea from the very beginning to use such a platform-specific and absolute path. Instead you should follow these instruction to adding-files-to-packaged-application and then set the following property very early in your desktop specific code.
Copy code
System.getProperty("compose.application.resources.dir")?.let { System.setProperty("java.library.path", "${System.getProperty("java.library.path")}${File.pathSeparator}${it}") }
In your case the library should be placed in
Copy code
desktopApp/resources/windows-x64/yourlibrary.dll