dev env: Ubuntu 10.10 (32-bit), Eclipse, OpenJDK
I currently have code for an executable written in C. I need to modify it to convert it to a .so library and access its functions from Java code.
Currently, the C code comprises 3 headers and 3 source files (.c). I need to call only the main function and pass two strings to it from java. All the rest of the functions are called from within main(). unfortunately, one of the other functions prints results to the command line. How do implement JNI to pass the two strings and return this particular result?
I found examples on the web but found them to be too simplistic.
Also I fail to locate the jni.h header for use.
Would I use JNIEXPORT int JNICALL Java_ppldtct_main(JNIEnv*,jobject,jstring,jstring) instead of the int main(int argc,char** argv) in C?
All the help much appreciated.
Thank you
If I understand you correctly, you are trying to do minimal changes in the existing code.
If that’s the case, you may try to overwrite the file descriptor 1 ( stdout ) with a pipe and get the output of the program this way.