SONO RIUSCITO A RIMEDIARE VISUAL C++
PERO' HO IL SEGUENTE PROBLEMA
Ho visto un esempio di creazione di un metodo nativo
Questa é la classe
public class NativeDemo {
int i;
public static void main(String args[]) {
NativeDemo ob = new NativeDemo();
ob.i = 10;
System.out.println("This is ob.i before the native method:" +
ob.i);
ob.test(); // call a native method
System.out.println("This is ob.i after the native method:" +
ob.i);
}
// declare native method
public native void test() ;
// load DLL that contains static method
static {
System.loadLibrary("NativeDemo");
}
}
Ho compilato la classe
Poi ho creato NativeDemo.h così
javah -jni NativeDemo
Il codice NativeDemo.c é il seguente
#include <jni.h>
#include "NativeDemo.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_NativeDemo_test(JNIEnv *env, jobject obj)
{
jclass cls;
jfieldID fid;
jint i;
printf("Starting the native method.\n");
cls = (*env)->GetObjectClass(env, obj);
fid = (*env)->GetFieldID(env, cls, "i", "I");
if(fid == 0) {
printf("Could not get field id.\n");
return;
}
i = (*env)->GetIntField(env, obj, fid);
printf("i = %d\n", i);
(*env)->SetIntField(env, obj, fid, 2*i);
printf("Ending the native method.\n");
}
Lo compilo con Visual C++ e mi da il seguente errore che non riesco a
trovare
Linking...
Creating library Debug/NativeDemo.lib and object Debug/NativeDemo.exp
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/NativeDemo.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
NativeDemo.exe - 2 error(s), 0 warning(s)
Ho messo jni.h e NativeDemo.h nella cartella include di Visual
Aiuto !!![]()

Rispondi quotando