I try to call this minimal C code (file TEST.c
):
void Java_TEST_run() {}
from this Java code (file Example.java
):
public class Example {
public static void main(String args[]) {
System.out.println("START");
TEST test = new TEST();
test.dll_call();
System.out.println("ALL DONE!");
}
}
class TEST {
public void dll_call() {
run();
}
static {
try {
System.out.println("Load DLL = start ");
System.load("/home/user/Desktop/TEST.dll");
System.out.println("Load DLL = finish ");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n");
System.exit(1);
}
}
public native void run();
}
I create a library in the following way:
gcc -c TEST.c
g++ -shared -o TEST.dll TEST.o
If I compile with GCC (and create lib even with G++!) everything works fine, but if I compile with G++ (g++ -c TEST.c
), I receive the following output with error, when running the Java example:
START
Load DLL = start
Load DLL = finish
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'void TEST.run()'
at TEST.run(Native Method)
at TEST.dll_call(Example.java:21)
at Example.main(Example.java:9)