Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.UnsatisfiedLinkError: no themis_jni in java.library.path: [C:\Users\me\Downloads\jdk-11.0.1\bin on Windows #897

Open
VisionaryAppDev opened this issue Jan 19, 2022 · 6 comments
Labels
O-Windows 🖥️ Operating system: Windows question

Comments

@VisionaryAppDev
Copy link

Hello Everyone,

Currently, I have tried installing Themis from source and most of the process is going pretty well but still there is some problem I got so far.

First, I have Themis core installed by following this tutorial without any problem on Windows. tutorial

Then, I have tried installing Themis language wrapper for Java and then thing start to get intent. The thing I noticed is that, JAVA_HOME must point to Linux JDK in other to make this make themis_jni build command run successfully. If I set my JAVA_HOME to Windows JDK, then there is some problem related to jni.h being missing.

Currently, I have tried setting JAVA_HOME to Linux JDK and make themis_jni build command is producing a few files:

$ make themis_jni
compile build/obj/jni/crypto_dummy.c.o                             [OK]
compile build/obj/jni/themis_cell.c.o                              [OK]
compile build/obj/jni/themis_compare.c.o                           [OK]
compile build/obj/jni/themis_jni.c.o                               [OK]
compile build/obj/jni/themis_keygen.c.o                            [OK]
compile build/obj/jni/themis_message.c.o                           [OK]
compile build/obj/jni/themis_session.c.o                           [OK]
link build/libthemis_jni.dll                                       [OK]

And for make themis_jni_install command, I also get some success output as well:

$ make themis_jni_install
install Themis JNI                                                 [OK]
bash: line 1: [: -eq: unary operator expected

Your Java installation does not seem to have "/usr/local/lib" in its
search path for JNI libraries:



You will need to either add it to the "java.library.path" property
on application startup, or to move libthemis_jni.dll manually
to one of these locations so that Java could find it.

Ok, after everything is done, I have copied libthemis_jni.dll into ../JDK/bin/ directory and run the example project. Since I am using Intellij, I have set the JVM Args to -Djava.library.path="full-path-of-jdk/bin"

After run, I got some error:

Running SecureCell example
Exception in thread "main" java.lang.UnsatisfiedLinkError: no themis_jni in java.library.path: [C:\Users\me\Downloads\jdk-11.0.1\bin, C:\Windows\Sun\Java\bin, C:\Windows\system32, C:\Windows, c:\app\client\me\product\19.0.0\client_1\bin, C:\Windows\system32, C:\Windows, C:\Windows\System32\Wbem, C:\Windows\System32\WindowsPowerShell\v1.0\, C:\Windows\System32\OpenSSH\, C:\Program Files\nodejs\, C:\Users\me\AppData\Local\Microsoft\WindowsApps, C:\Users\me\AppData\Local\Programs\Git\cmd, E:\SYSTEM\jdk-11.0.1\bin, E:\SYSTEM\apache-maven-3.6.0\bin, ., C:\Users\me\AppData\Local\Programs\Microsoft VS Code\bin, C:\Users\me\AppData\Roaming\npm, .]
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
	at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
	at java.base/java.lang.System.loadLibrary(System.java:1867)
	at com.cossacklabs.themis.SecureCell.<clinit>(SecureCell.java:114)
	at main.encryptDataForStoring(main.java:31)
	at main.main(main.java:20)

Execution failed for task ':app:main.main()'.
> Process 'command 'C:/Users/me/Downloads/jdk-11.0.1/bin/java.exe'' finished with non-zero exit value 1

Please let me know if I did some wrong here. Thanks

@ilammy
Copy link
Collaborator

ilammy commented Jan 19, 2022

JavaThemis calls System.loadLibrary("themis_jni") and the translation to actual library file name happens in a platform-specific manner. I'd expect that Windows JRE might expect to find themis_jni.dll exactly, without a lib- prefix customary in UNIX environments.

Does renaming libthemis_jni.dll to just themis_jni.dll change anything?

Another thing that might be wrong here is that JNI DLL might be not self-sufficient. On Windows, Themis builds itself for MSYS2 environment and expects a bunch of MSYS DLLs to be loaded along with it. I don't remember off the top of my head the exact way to list dependencies of a DLL, but you'd might to do that as well and copy over extra libraries.

@VisionaryAppDev
Copy link
Author

Hello @ilammy,

I have tried renaming "libthemis_jni.dll" to "themis_jni.dll" and "themis_jni" and the application got another error instead.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:main.main()'.
> Process 'command 'C:/Users/me/Downloads/jdk-11.0.1/bin/java.exe'' finished with non-zero exit value -1073741819

For other dependency, I have copied all from "/usr/local/lib" and many other location and stored it inside "themis/some-path/docs/example/java/libs". Here is the tree structure of all the files I have as the dependency:

bin:

  • msys-soter-0.dll
  • msys-themis-0.dll

include:

  • soter:

    • soter.h
    • soter_api.h
    • soter_asym_cipher.h
    • soter_asym_ka.h
    • soter_asym_sign.h
    • soter_error.h
    • soter_hash.h
    • soter_hmac.h
    • soter_kdf.h
    • soter_rand.h
    • soter_rsa_key_pair_gen.h
    • soter_sym.h
    • soter_wipe.h
    • libsoter.a
    • libsoter.dll.a
    • libthemis.a
    • libthemis.dll.a
  • themis:

    • secure_cell.h
    • secure_comparator.h
    • secure_keygen.h
    • secure_message.h
    • secure_session.h
    • themis.h
    • themis_api.h
    • themis_error.h

lib:

  • pkgconfig:
    • libsoter.pc
    • libthemis.pc
  • libsoter.a
  • libsoter.dll.a
  • libthemis.a
  • libthemis.dll.a

I have also set dependency directory inside build.gradle of the app:

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

And lastly, specify "-Djava.library.path" inside Intellij JVM args to "themis/some-path/docs/example/java/libs".

But, sadly, it still doesn't work.

@vixentael vixentael added O-Windows 🖥️ Operating system: Windows question labels Jan 19, 2022
@vixentael
Copy link
Contributor

I'm not a Windows user, but the googling of "finished with non-zero exit value -1073741819" lead me to different results.

For example, here (the guide is targeted on end users, not developers) they believe that the issue is related to file access. Here people complain on Android SDK build tools.

@VisionaryAppDev could you tell us more which Windows version do you use (version, is it 32-bit of 64-bit)?
As I understood, you are using jdk-11.0.1.
Is your java environment healthy (do you typically run java apps without issues)?

@ilammy
Copy link
Collaborator

ilammy commented Jan 19, 2022

The exit code is for “access violation” error, which suggests that the issue here runs deeper.

Rereading your message, I believe the issue here might be in mixing JDKs. JNI libraries are DLLs but they are not completely self-sufficient and compatible, even on the same OS. That's even not considering the differences between JDK versions. If a DLL is built with MSYS2 GCC compiler to be loaded in MSYS2 environment – it might not be compatible with DLLs built by MSVC, which is what Windows JRE might expect. While it looks like a 64-bit DLL, functions might be using different calling conventions, which ultimately leads to a failure.

Sadly, at the moment, Windows support is still experimental not really actively worked on, so I don't have any more quick suggestions to try.

From what it appears, in order to build themis_jni.dll that could be loaded by IntelliJ's Java, you'd need to build Themis with MSVC (and use a compatible OpenSSL). That's... not really well-supported at the moment. I vaguely remember that using Makefile didn't work for me that well as it was not enough to just set CC=CL.EXE, LD=LINK.EXE, since the Makefile uses GCC-style command line. I do remember that I was able to build Themis with Visual Studio, by creating a new solution, adding all the source files there, and using Shining Light's OpenSSL builds. However, I didn't try building JNI back then, so no idea what hurdles that entails.

@VisionaryAppDev
Copy link
Author

Hello @vixentael ,

I have x64 bit JDK installed on my PC. And everything such as Intellij, Webstorm, and something like dbeaver are working pretty well.

@VisionaryAppDev
Copy link
Author

Thank you, @ilammy for your lengthy explanation. Seem like it is a lot complicated on Windows than on Linux and Mac OS. Maybe I could consider trying again the future or request my team to look into Linux instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-Windows 🖥️ Operating system: Windows question
Projects
None yet
Development

No branches or pull requests

3 participants