[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-debug-dev] question on how cdt make JNI call?
|
First, verify native methods signature in C code. It should be exactly
the same as javah generated. In your case they I wrong I suppose. You
can see how valid names look like in spawner.dll sources. Your names
miss package signature. It should be:
Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_greeting(...)
I guess you've got wrong header because you ran javah from the wrong
working directory.
Regards,
Alex.
Yan Chen wrote:
Hi,all!!!
I know this question maybe should not be asked in this mailing list, but
my question is somehow related to CDT codes. So any help is
appreciated!!!
My plugin need to load dynamic library and make JNI call, but until now
I do not have any luck. Under terminal I can load .so and make JNI call
without any problem, but I have no idea why my eclipse plugin can not
make JNI call(by using system.load() or system.loadLibrary()). To
access native libraries in eclipse Do I need to set up correctly the
path in the plugin.xml? and how?
By reading CDT code, I found CDT also make JNI call, so I did a test as
follows:
I first made libSpawnerOutputStream.so and then I put it in the
directory org.eclipse.cdt.core.linux/os/linux/x86 where libspawner.so
is. Then I added my stuff in the class SpawnerOutputStream as follows:
public class SpawnerOutputStream extends OutputStream {
public void write(byte[] b, int off, int len) throws IOException
{
write0(fd, tmpBuf, len);
/*****My stuff**********/
greeting();
/*****My stuff**********/
}
private native int write0(int fd, byte[] b, int len) throws
IOException;
private native int close0(int fd);
/*****My stuff**********/
public static native void greeting();
/*****My stuff**********/
static {
System.loadLibrary("spawner"); //$NON-NLS-1$
/*****My stuff**********/
System.loadLibrary("SpawnerOutputStream");
/*****My stuff**********/
}
}
But when I start debugging a c program, I got the following error:
java.lang.UnsatisfiedLinkError: greeting
at
org.eclipse.cdt.utils.spawner.SpawnerOutputStream.greeting(Native
Method)
at
org.eclipse.cdt.utils.spawner.SpawnerOutputStream.write(SpawnerOutputStr
eam.java:50)
at java.io.OutputStream.write(OutputStream.java:58)
at org.eclipse.cdt.debug.mi.core.TxThread.run(TxThread.java:72)
Could someone help me out? Thanks in advance!!!
Johnny
P.S. The following codes are for making .so file
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class SpawnerOutputStream */
#ifndef _Included_SpawnerOutputStream
#define _Included_SpawnerOutputStream
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: SpawnerOutputStream
* Method: greeting
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_SpawnerOutputStream_greeting
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
/**
* @version 1.10 1997-07-01
* @author Cay Horstmann
*/
#include "SpawnerOutputStream.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_SpawnerOutputStream_greeting
(JNIEnv* env, jclass cl)
{ printf("Hello world!\n");
}
_______________________________________________
cdt-debug-dev mailing list
cdt-debug-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/cdt-debug-dev