Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with JNI

0 views
Skip to first unread message

pradeep

unread,
Apr 28, 2004, 3:02:35 AM4/28/04
to
Hello,
We are trying to access some C++ functions using JNI on Solaris platform.
We wrote a cpp implementation file and used the header generated using
javah.
We compiled and linked using CC.
The command we used was (/vobs/devtools/java_sdk is the path for java_sdk)
CC
myJava.cxx -I/vobs/devtools/java_sdk/include -l/vobs/devtools/java_sdk/inclu
de/solaris -G -o libmylib.so

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


0 new messages