Results 1 to 14 of 14
  1. #1
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default jni.h: No such file or directory

    In file included from A.c:1:
    A.h:2:17: error: jni.h: No such file or directory
    In file included from A.c:1:
    A.h:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
    A.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    class A
    {
    static
    { System.loadLibrary("A"); }

    public native void print();

    public static void main(String[] args)
    {
    new A().print();
    }
    }

    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class A */

    #ifndef _Included_A
    #define _Included_A
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
    * Class: A
    * Method: print
    * Signature: ()V
    */
    JNIEXPORT void JNICALL Java_A_print
    (JNIEnv *, jobject);

    #ifdef __cplusplus
    }
    #endif
    #endif

    #include "A.h"
    #include "stdio.h"

    JNIEXPORT void JNICALL Java_A_print
    (JNIEnv *x, jobject y)
    {
    printf("Welcome To Land Of Java-C\n");
    }

    when i compile last file i get the above mention errors!!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by roadies07 View Post
    In file included from A.c:1:
    A.h:2:17: error: jni.h: No such file or directory
    In file included from A.c:1:
    A.h:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
    A.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
    That is just a C/C++ compiler setting; the missing header file is in your JDK in the include subdirectory; add that directory to your include list with the -I flag.

    kind regards,

    Jos

  5. #5
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    actually jni.h is present inside the java directory
    locate jni.h
    /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/include/jni.h

    can u give the full command to compile it

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by roadies07 View Post
    actually jni.h is present inside the java directory
    locate jni.h
    /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/include/jni.h
    Yes, that's what I wrote in my previous reply.

    Quote Originally Posted by roadies07 View Post
    can u give the full command to compile it
    So you don't know how your C/C++ compiler works? As I already wrote in my previous reply: use the -I flag when you want to compile something:

    Java Code:
    cc -I<directory where jni.h file is stored> <your .c file>
    kind regards,

    Jos

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    That is just a C/C++ compiler setting; the missing header file is in your JDK in the include subdirectory; add that directory to your include list with the -I flag.

    kind regards,

    Jos
    From where I can find those settings? Can you elaborate please.

  8. #8
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    @Eranga: Its a C++ compiler thing. The only way to do anything about them is with command line options, and the odd environment variable.

    @OP: JosAH is right, you need to use -I to add a path to the header. However, feel I should add that you probably need to add a system-dependent path as well, to a header included by jni.h. For me, its something like -I%JAVA_HOME%/include/win32/jni_md.h. For you, it won't be the same, as I'd guess you're running a unix box of some sort judging by the path you mentioned
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Singing Boyo View Post
    @Eranga: Its a C++ compiler thing. The only way to do anything about them is with command line options, and the odd environment variable.
    I don't want to test it then.

  10. #10
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Quote Originally Posted by Eranga View Post
    I don't want to test it then.
    I'd suggest you don't then :) setting up JNI is a pain... the worst part for me being the necessity of editing jni.h so the JVM would find my native functions...
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Eranga View Post
    From where I can find those settings? Can you elaborate please.
    It's in your C/C++ compiler's manual; usually (by convention) it is the -I<dir to include> command line flag as I already wrote in my previous reply.

    kind regards,

    Jos

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Singing Boyo View Post
    I'd suggest you don't then :) setting up JNI is a pain... the worst part for me being the necessity of editing jni.h so the JVM would find my native functions...
    By experience I know that editing headers are real pain. ;)

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    It's in your C/C++ compiler's manual; usually (by convention) it is the -I<dir to include> command line flag as I already wrote in my previous reply.
    I've never see this in C/C++ compiler. Interesting to check it out.

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Singing Boyo View Post
    @OP: JosAH is right, you need to use -I to add a path to the header. However, feel I should add that you probably need to add a system-dependent path as well, to a header included by jni.h. For me, its something like -I%JAVA_HOME%/include/win32/jni_md.h. For you, it won't be the same, as I'd guess you're running a unix box of some sort judging by the path you mentioned
    No, you don't have to do that: the md.h (Machine Description) file is included by the jni.h file, so it is done for you. All you have to do is set your include path(s) right and include the generated .h file (it contains the prototypes of your native functions) and included jni.h for you. It's just an ordinary C environment setup.

    kind regards,

    Jos

Similar Threads

  1. directory file list....
    By viewer in forum New To Java
    Replies: 11
    Last Post: 05-22-2010, 04:19 PM
  2. Openening a File in Any Directory
    By dpedroia15 in forum New To Java
    Replies: 1
    Last Post: 03-21-2010, 11:56 PM
  3. Replies: 2
    Last Post: 05-11-2009, 10:07 AM
  4. [SOLVED] File chooser selecting file from directory...?
    By prabhurangan in forum AWT / Swing
    Replies: 12
    Last Post: 06-18-2008, 04:08 AM
  5. How to Move a File to Another Directory
    By Ada in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 01:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •