Hallo, ich bin derzeit dabei, aus Java heraus C-Programme auszuführen... d. h. ich versuche es noch.
Ein Vorbereitungsschritt ist, den C-Code in ein ladbares Objekt zu kompilieren. Dazu habe ich exakt folgende Schritte ausgeführt, wie es im Buch stand ...
<br><br>
set JAVA_HOME=c:/programme/java<br>
set INCLUDE=%JAVA_HOME%\include;%JAVA_HOME%<br>\includ e\win32;%INCLUDE%<br>
set LIB=%JAVA_HOME%\lib;%LIB%<br>
cl HelloWorld.c -Fehello.dll -MD -LD javai.lib<br><br>
Fehlermeldung --><br>
error HelloWorld.c(11)C2373: 'Java_HelloWorld_displayHelloWorld': redefinition; different type modifiers,<br>
HelloWorld.h(15) : see declaration of 'Java_HelloWorld_displayHelloWorld'<br><br>
Die Codes sehen wie folgt aus: <br><br>
Helloworld.c
<pre>
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
#ident "$Id: HelloWorld.c,v 1.4 2000/07/03 23:15:49 ian Exp $"
/*
* This is the 1.1 implentation of displayHelloWorld.
*/
void Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject this)
{
jfieldID fldid;
jint n, nn;
(void)printf("Hello from a Native Method\n");
if (this == NULL) {
fprintf(stderr, "Input pointer is null!\n");
return;
}
if ((fldid = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, this), "myNumber", "I")) == NULL) {
fprintf(stderr, "GetFieldID failed");
return;
}
n = (*env)->GetIntField(env, this, fldid); /* retrieve myNumber */
printf("\"myNumber\" value is %d\n", n);
(*env)->SetIntField(env, this, fldid, ++n); /* increment it! */
nn = (*env)->GetIntField(env, this, fldid);
printf("\"myNumber\" value now %d\n", nn); /* make sure */
return;
}
</pre>
<br>HelloWorld.h
<pre>
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld (JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
</pre>
<br><br>
<b>Was mache ich falsch ? Was muss ich tun, damit die Sache funktioniert ?</b><br><br>
ANDI
Ein Vorbereitungsschritt ist, den C-Code in ein ladbares Objekt zu kompilieren. Dazu habe ich exakt folgende Schritte ausgeführt, wie es im Buch stand ...
<br><br>
set JAVA_HOME=c:/programme/java<br>
set INCLUDE=%JAVA_HOME%\include;%JAVA_HOME%<br>\includ e\win32;%INCLUDE%<br>
set LIB=%JAVA_HOME%\lib;%LIB%<br>
cl HelloWorld.c -Fehello.dll -MD -LD javai.lib<br><br>
Fehlermeldung --><br>
error HelloWorld.c(11)C2373: 'Java_HelloWorld_displayHelloWorld': redefinition; different type modifiers,<br>
HelloWorld.h(15) : see declaration of 'Java_HelloWorld_displayHelloWorld'<br><br>
Die Codes sehen wie folgt aus: <br><br>
Helloworld.c
<pre>
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
#ident "$Id: HelloWorld.c,v 1.4 2000/07/03 23:15:49 ian Exp $"
/*
* This is the 1.1 implentation of displayHelloWorld.
*/
void Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject this)
{
jfieldID fldid;
jint n, nn;
(void)printf("Hello from a Native Method\n");
if (this == NULL) {
fprintf(stderr, "Input pointer is null!\n");
return;
}
if ((fldid = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, this), "myNumber", "I")) == NULL) {
fprintf(stderr, "GetFieldID failed");
return;
}
n = (*env)->GetIntField(env, this, fldid); /* retrieve myNumber */
printf("\"myNumber\" value is %d\n", n);
(*env)->SetIntField(env, this, fldid, ++n); /* increment it! */
nn = (*env)->GetIntField(env, this, fldid);
printf("\"myNumber\" value now %d\n", nn); /* make sure */
return;
}
</pre>
<br>HelloWorld.h
<pre>
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld (JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
</pre>
<br><br>
<b>Was mache ich falsch ? Was muss ich tun, damit die Sache funktioniert ?</b><br><br>
ANDI
Comment