Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Implementation of a native method in C++

Implementation in C++ is largely identical to the procedure used for implementation in C. The differences from the example above are as follows:

Program Hello.cpp is now implemented as follows:

#include <jni.h>
#include "Hello.h"
#include <iostream.h>
#include <ascii_ebcdic.h>
#include <stdlib.h>
JNIEXPORT void JNICALL
Java_Hello_greetings(JNIEnv *env, jobject jthis, jstring text)
{
  char *ebcdic_text;
  const char *utf_text;
  utf_text = env->GetStringUTFChars(text,NULL);
  ebcdic_text = _a2e_dup(utf_text);
  env->ReleaseStringUTFChars(text,utf_text);
  cout <<  "The program responds here" << ebcdic_text << endl;
  free(ebcdic_text);
}

For compilation, instead of using command cc, use command CC. For creation of the shared object, the flag cpp must be set:

mk_shobj -f cpp -l syslnk.example1 -m example1 libexample1.so