Some C++ functions not working when using jni : UNSATISFIED LINKER IN JAVA

I am writing a function for java in c++.

There are some functions which i intent to use only in the c++ code

here is the code:

#include <jni.h>
#include <iostream>
#include <ncurses.h>
#include "Driver.h"
using namespace std;

JNIEXPORT void JNICALL Java_Driver_func(JNIEnv *env, jobject){
    initscr();          /* Start curses mode          */
    printw("Hello World !!!");  /* Print Hello World          */
    refresh();          /* Print it on to the real screen */
    getch();            /* Wait for user input */
    endwin();
    return;
}

Error :

$java -Djava.library.path=. Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: /path/to/mylib.so: /path/to/mylib.so: undefined symbol: stdscr
    at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
    at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442)
    at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498)
    at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2659)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830)
    at java.base/java.lang.System.loadLibrary(System.java:1873)
    at Driver.<clinit>(Driver.java:3)
    at Main.main(Main.java:4)

NOTE: I changed the paths from the error to /path/to/mylib.so but thats ok i guess!

Source: Windows Questions C++

LEAVE A COMMENT