Juneyoung Oh
Juneyoung Oh

Reputation: 7652

jni.h and expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’

My working environment is mac OSX 10.8.3.

now I'm testing JNI.

I made HelloJNI.java file and execute javac and javah command in terminal.

So I got HelloJNI.java, HelloJNI.class, org_owls_jni_HelloJNI.h files.

then I put

gcc -g -l/usr/local/java/include -l/usr/local/java/include/linux -shared HelloJNI.c -o libhello.so

command to run program. And faced with 2 error messages.

  1. jni.h: No such file or directory
  2. expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘void’

I've searched internet and found a solution which says upgrade my jdk to 1.7. But I can not do that because other people uses 1.6. So I need another solution to handle this problem with jdk 1.6.

For second problem, I found some article in stackoverflow. they say they were missing some syntax. But for me, I can not find any problems before void. please, take a look my header file.

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

#ifndef _Included_org_owls_jni_HelloJNI
#define _Included_org_owls_jni_HelloJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     org_owls_jni_HelloJNI
 * Method:    printMessage
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_org_owls_jni_HelloJNI_printMessage
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

I think here's no problem, because it was automatically generate by command javah.

I thank you very much for your advises in advanced.

Upvotes: 1

Views: 1908

Answers (1)

paxdiablo
paxdiablo

Reputation: 882048

Your first error is because you don't have a jni.h, it's that simple. You have to find out where it is and ensure it's on your include path.

And, by the way, that's done in gcc with -I (upper case eye), not -l (lower case ell). The latter is for specifying libraries to use rather than directories to add to the include path. That is, I believe, your specific problem here.

The second error is caused by the first, it's because you have this unknown token before void in:

JNIEXPORT void JNICALL Java_org_owls_jni_HelloJNI_printMessage

no doubt because of the missing jni.h.

Upvotes: 2

Related Questions