When I invoke the java program with the following command,
java myJava
I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/home/om1/rJNI/libmylib.so: ld.so.1:
/vobs/devtools/java_sdk/bin/../bin/sparc/native_threads/java: fatal:
relocation error: file /home/om1/rJNI/libmylib.so: symbol __1cDstdEcout_:
referenced symbol not found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1382)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
at java.lang.Runtime.loadLibrary0(Runtime.java:749)
at java.lang.System.loadLibrary(System.java:820)
at myJava.<clinit>(myJava.java:6)
It seems to be not finding the symbol std::cout. How do I resolve this
problem?
The C++ code and Java program are listed below.
C++ Source:
#include <fstream>
using namespace std;
#include "myJava.h"
#include <jni.h>
class rsample
{
public:
int var1;
};
JNIEXPORT void JNICALL Java_myJava_displayMsg(JNIEnv* env, jobject obj)
{
cout<<"My Message";
int i=10;
rsample robj;
robj.var1=i;
return;
}
Java Program myJava.java
class myJava
2 {
3 public native void displayMsg();
4
5 static{
6 System.loadLibrary("mylib");
7 }
8
9 public static void main(String args[])
10 {
11 new myJava().displayMsg();
12 }
13 }
14
Best Regards,
Pradeep