Announcement

Collapse
No announcement yet.

C-Kompilieren für JNI

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • C-Kompilieren für JNI

    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%
    \include\win32;%INCLUDE%<br>
    set LIB=%JAVA_HOME%\lib;%LIB%<br>
    cl HelloWorld.c -Fehello.dll -MD -LD javai.lib
    <br><br> <br><br>
    Fehlermeldung --><br>
    error HelloWorld.c(11)C2373: 'Java_HelloWorld_displayHelloWorld': redefinition; different type modifiers,
    HelloWorld.h(15) : see declaration of 'Java_HelloWorld_displayHelloWorld'
    <br><br>
    Die Codes sehen wie folgt aus:
    <br><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>
    <b>Was mache ich falsch ? Was muss ich tun, damit die Sache funktioniert ?</b>
    <br><br>
    ANDI <br><br><br>
    P.S. Bitte spart Euch den Ratschlag, damit ins C++-Forum zu gehen! Die haben mich gerade hierher geschickt!

  • #2
    Hast Du mal versucht, die Signatur der Funktion Java_HelloWorld_displayHelloWorld aus dem *.h-File im *.c-File 1:1 zu uebernehmen

    Comment

    Working...
    X