jni problem [message #686313] |
Wed, 22 June 2011 02:23 |
James Wolfe Messages: 5 Registered: June 2011 |
Junior Member |
|
|
I am learning to use JNI.
I created a java source file, a header file and the shared object library all outside
of eclipse.
Everything runs fine.
Next I imported the java source into a package of my eclipse project.
Eclipse compiled the java source.
I then went to the bin directory in the eclipse project.
I ran javah to create the header file.
I copied the header file to the project package folder.
I compiled the shared object library from the command line (gcc...).
The loadLibrary seems to work, but the call to the native function is not found.
Java is looking for a native function with the java package name as a prefix.
java.lang.UnsatisfiedLinkError: irSensor.ExternalSignatureNoiseCCPP.printfString(Ljava/lang/String;D)I
The shared object library does not know about the package name.
Am I going about this all wrong.
I have the CDT plugin installed but for starters I thought I would try the approach
above.
Function call code..............................
public boolean doNoiseRawSignature(String command, DiscrimConfig config,
MyJFrame myJF, String mode) {
boolean error = false;
Map<String, Signature> rawSigs = config.getSignaturesRaw();
MyLog.logStartOfOperation(command + ": " + "Raw "
+ "C / C++", myJF);
Random rand = new Random();
ExternalSignatureNoiseCCPP esnccpp = new ExternalSignatureNoiseCCPP();
int count = 0;
System.out.println("\n" + "Java sent a string and a double.\n");
count = esnccpp.printfString("pi = ", 3.14159265);
System.out.println("java received an integer: " + count);
System.out.println();
Java source .......................................
package irSensor;
public class ExternalSignatureNoiseCCPP {
static {
System.loadLibrary("ExternalSignatureNoiseCCPP");
}
public ExternalSignatureNoiseCCPP(){
}
public native int printfString(String s, double x);
}
C code ............................................
#include <jni.h>
#include "ExternalSignatureNoiseCCPP.h"
#include <stdio.h>
JNIEXPORT jint JNICALL Java_ExternalSignatureNoiseCCPP_printfString
(JNIEnv *env, jobject obj, jstring str, jdouble x)
{
jboolean iscopy;
const char *message = (*env)->GetStringUTFChars(
env, str, &iscopy);
printf("C received:\n%s%f\n\n", message, x);
jint ret;
ret = 1;
fflush(stdout);
return ret;
}
Thanks, Paul
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02243 seconds