Java zu C ++ JNI DLL ERRAGE - Java.lang.unsatisfiedLinkError: ... kann keine abhängigen Bibliotheken findenJava

Java-Forum
Anonymous
 Java zu C ++ JNI DLL ERRAGE - Java.lang.unsatisfiedLinkError: ... kann keine abhängigen Bibliotheken finden

Post by Anonymous »

Jahre hatte ich ein Beispiel für Java- und C ++ - Programme, die über JNI und Laufen verbunden waren. C: \ Benutzer \ bike1 \ jnitest \ hellocpp.dll: Ich kann abhängige Bibliotheken nicht finden. Ich kann keine zusätzlichen Debugging-Informationen finden, die mir helfen. (x86_64-w64-mingw32)). />

Code: Select all

file: compile.bat
@echo on
echo compile java class
set JAVA_HOME=C:\Users\Public\wpilib\2025\jdk
javac -version
type %JAVA_HOME%\release
javac HelloJNI.java
javap -p -s HelloJNI
echo generate header file
javac -h . HelloJNI.java
echo compile DLL
g++ -v
g++ -v -m64 -Wl,--add-stdcall-alias -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" -shared -o HelloCpp.dll main.cpp
echo run java program
java -Djava.library.path=. HelloJNI
rem java HelloJNI
echo Clean up
dir
del *.class; del *.dll, del *.h
pause
< /code>
file: output.txt
C:\Users\bike1\JNItest>compile

C:\Users\bike1\JNItest>echo compile java class
compile java class

C:\Users\bike1\JNItest>set JAVA_HOME=C:\Users\Public\wpilib\2025\jdk

C:\Users\bike1\JNItest>javac -version
javac 17.0.12

C:\Users\bike1\JNItest>type C:\Users\Public\wpilib\2025\jdk\release
IMPLEMENTOR="Eclipse Adoptium"
IMPLEMENTOR_VERSION="Temurin-17.0.12+7"
...
C:\Users\bike1\JNItest>javac HelloJNI.java

C:\Users\bike1\JNItest>javap -p -s HelloJNI
Compiled from "HelloJNI.java"
...
C:\Users\bike1\JNItest>echo generate header file
generate header file

C:\Users\bike1\JNItest>javac -h .  HelloJNI.java

C:\Users\bike1\JNItest>echo compile DLL
compile DLL

C:\Users\bike1\JNItest>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/Program\ Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
...
C:\Users\bike1\JNItest>g++ -v -m64 -Wl,--add-stdcall-alias -I"C:\Users\Public\wpilib\2025\jdk\include" -I"C:\Users\Public\wpilib\2025\jdk\include\win32" -shared -o HelloCpp.dll main.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/Program\ Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-src/configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-bootstrap --enable-targets=all --enable-languages=c,c++,lto --enable-seh-exceptions --with-arch=core2 --with-tune=generic --enable-threads=posix --disable-nls --enable-shared=libstdc++ --enable-static --enable-libatomic --enable-fully-dynamic-string --enable-lto --enable-plugins --enable-libgomp --with-dwarf2 --enable-mingw-wildcard=platform --disable-win32-registry --enable-version-specific-runtime-libs --enable-checking=release --enable-default-compressed-debug-sections-algorithm=zstd --disable-cloog-version-check --enable-cloog-backend=isl --with-gmp=/home/vm/mingw/host/x86_64-w64-mingw32 --with-mpfr=/home/vm/mingw/host/x86_64-w64-mingw32 --with-mpc=/home/vm/mingw/host/x86_64-w64-mingw32 --with-isl=/home/vm/mingw/host/x86_64-w64-mingw32 --with-cloog=/home/vm/mingw/host/x86_64-w64-mingw32 --with-system-zlib=/home/vm/mingw/host/x86_64-w64-mingw32 --with-zstd --prefix=/mingw64-64 --libdir=/mingw64-64/x86_64-w64-mingw32/lib --libexecdir=/mingw64-64/x86_64-w64-mingw32/lib --with-native-system-header-dir=/x86_64-w64-mingw32/include
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.1.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-m64' '-I' 'C:\Users\Public\wpilib\2025\jdk\include' '-I' 'C:\Users\Public\wpilib\2025\jdk\include\win32' '-shared' '-o' 'HelloCpp.dll' '-mtune=generic' '-march=core2' '-dumpdir' 'HelloCpp.dll-'
C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/cc1plus.exe -quiet -v -I C:\Users\Public\wpilib\2025\jdk\include -I C:\Users\Public\wpilib\2025\jdk\include\win32 -iprefix C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/ -D__USE_MINGW_ACCESS -D_REENTRANT main.cpp -quiet -dumpdir HelloCpp.dll- -dumpbase main.cpp -dumpbase-ext .cpp -m64 -mtune=generic -march=core2 -version -o C:\Users\bike1\AppData\Local\Temp\ccPb8TDw.s
GNU C++17 (GCC) version 15.1.0 (x86_64-w64-mingw32)
compiled by GNU C version 15.1.0, GMP version 6.3.0, MPFR version 4.2.2, MPC version 1.2.1, isl version isl-0.27-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "C:/Program Files/mingw64/x86_64-w64-mingw32/lib/gcc/../../../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include/c++"
ignoring duplicate directory "C:/Program Files/mingw64/x86_64-w64-mingw32/lib/gcc/../../../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include/c++/x86_64-w64-mingw32"
ignoring duplicate directory "C:/Program Files/mingw64/x86_64-w64-mingw32/lib/gcc/../../../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include/c++/backward"
ignoring duplicate directory "C:/Program Files/mingw64/x86_64-w64-mingw32/lib/gcc/../../../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include"
ignoring duplicate directory "C:/Program Files/mingw64/x86_64-w64-mingw32/lib/gcc/../../../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include-fixed"
ignoring duplicate directory "C:/Program Files/mingw64/x86_64-w64-mingw32/lib/gcc/../../../include"
#include "..." search starts here:
#include   search starts here:
C:\Users\Public\wpilib\2025\jdk\include
C:\Users\Public\wpilib\2025\jdk\include\win32
C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include/c++
C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include/c++/x86_64-w64-mingw32
C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include/c++/backward
C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include
C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/include-fixed
C:/Program Files/mingw64/x86_64-w64-mingw32/lib/gcc/../../../include
C:/Program Files/mingw64/x86_64-w64-mingw32/lib/gcc/../../../x86_64-w64-mingw32/include
End of search list.
Compiler executable checksum: df2c0fc215a6149be467677878bc5191
COLLECT_GCC_OPTIONS='-v' '-m64' '-I' 'C:\Users\Public\wpilib\2025\jdk\include' '-I' 'C:\Users\Public\wpilib\2025\jdk\include\win32' '-shared' '-o' 'HelloCpp.dll' '-mtune=generic' '-march=core2' '-dumpdir' 'HelloCpp.dll-'
C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../../x86_64-w64-mingw32/bin/as.exe -v -I C:\Users\Public\wpilib\2025\jdk\include -I C:\Users\Public\wpilib\2025\jdk\include\win32 --64 -o C:\Users\bike1\AppData\Local\Temp\ccLDFbsN.o C:\Users\bike1\AppData\Local\Temp\ccPb8TDw.s
GNU assembler version 2.44 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.44
COMPILER_PATH=C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/;C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/;C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/;C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/;C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../../x86_64-w64-mingw32/lib//../../x86_64-w64-mingw32/lib/;C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../..//../../x86_64-w64-mingw32/lib/;C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../../x86_64-w64-mingw32/lib/;C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../
COLLECT_GCC_OPTIONS='-v' '-m64' '-I' 'C:\Users\Public\wpilib\2025\jdk\include' '-I' 'C:\Users\Public\wpilib\2025\jdk\include\win32' '-shared' '-o' 'HelloCpp.dll' '-mtune=generic' '-march=core2' '-dumpdir' 'HelloCpp.dll.'
C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/collect2.exe -plugin C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/liblto_plugin.dll -plugin-opt=C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\bike1\AppData\Local\Temp\ccp6N7Sb.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -m i386pep --shared -Bdynamic -e DllMainCRTStartup --enable-auto-image-base -o HelloCpp.dll C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../../x86_64-w64-mingw32/lib//../../x86_64-w64-mingw32/lib/dllcrt2.o C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/crtbegin.o -LC:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0 -LC:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc -LC:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../../x86_64-w64-mingw32/lib//../../x86_64-w64-mingw32/lib -LC:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../..//../../x86_64-w64-mingw32/lib -LC:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../../x86_64-w64-mingw32/lib -LC:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/../../..  --add-stdcall-alias C:\Users\bike1\AppData\Local\Temp\ccLDFbsN.o -lstdc++ -lmingw32 -lgcc -lmingwex -lmsvcrt -lkernel32 -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lmingwex -lmsvcrt -lkernel32 C:/Program Files/mingw64/bin/../x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/15.1.0/crtend.o
COLLECT_GCC_OPTIONS='-v' '-m64' '-I' 'C:\Users\Public\wpilib\2025\jdk\include' '-I' 'C:\Users\Public\wpilib\2025\jdk\include\win32' '-shared' '-o' 'HelloCpp.dll' '-mtune=generic' '-march=core2' '-dumpdir' 'HelloCpp.dll.'

C:\Users\bike1\JNItest>echo run java program
run java program

C:\Users\bike1\JNItest>java -Djava.library.path=. HelloJNI
starting static block
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\bike1\JNItest\HelloCpp.dll: Can't find dependent libraries
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:287)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2427)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1993)
at HelloJNI.(HelloJNI.java:7)

C:\Users\bike1\JNItest>rem java HelloJNI

C:\Users\bike1\JNItest>echo Clean up
Clean up

C:\Users\bike1\JNItest>dir
Volume in drive C is Windows
Volume Serial Number is D28C-69C9

Directory of C:\Users\bike1\JNItest

08/18/2025  01:37 PM              .
08/18/2025  12:43 PM              ..
08/18/2025  01:37 PM               507 compile.bat
08/18/2025  01:37 PM               419 Hello.class
08/18/2025  01:37 PM            70,429 HelloCpp.dll
08/18/2025  01:37 PM             3,609 HelloJNI.class
08/18/2025  01:37 PM             2,094 HelloJNI.h
08/18/2025  12:40 PM             3,376 HelloJNI.java
08/18/2025  11:25 AM            10,838 main.cpp
08/18/2025  12:48 PM            14,481 output.txt
8 File(s)        105,753 bytes
2 Dir(s)  788,597,280,768 bytes free

C:\Users\bike1\JNItest>del *.class; del *.dll, del *.h

C:\Users\bike1\JNItest>pause
Press any key to continue . .  .

C:\Users\bike1\JNItest>
< /code>
file: main.cpp
#include 
#include 
#include 
#include 
#include "HelloJNI.h"

using namespace std;

static jclass intClass;

JNIEXPORT jdouble JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject obj, jint n1, jstring s){
//get the jstring
const char *str = env->GetStringUTFChars(s, 0);
if (str == NULL) return 0.0;
cout FindClass("java/lang/Integer");

//you can save a integer class reference to a global reference for later use (you can't do that for jmethodID and jfieldID they aren't objects)
intClass = (jclass) env->NewGlobalRef(tempIntClass);
//no longer need the local reference
env->DeleteLocalRef(tempIntClass);

//get the methodID of the constructor which takes an int
jmethodID mInit = env->GetMethodID(intClass, "", "(I)V");
if (NULL == mInit) return NULL;
//call back constructor to allocate a new instance with int argument
jobject intObj = env->NewObject(intClass, mInit, number);

//call to call ToString() on this object
jmethodID mToString = env->GetMethodID(intClass, "toString", "()Ljava/lang/String;");
if (NULL == mToString) return NULL;

jstring in_str = (jstring) env->CallObjectMethod(intObj, mToString);
const char* out_str = env->GetStringUTFChars(in_str, NULL);
cout

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post