Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

java native interface - Error when compiling in cygwin -- error: unknown type name '_int64' -- (jni.h)

After I run the following command, then I receive an error

gcc prog.c -o prog -I"C:/Program Files/Java/jdk1.8.0_25/include" -I"C:/Program Files/Java/jdk1.8.0_25/include/win32"

error: unknown type name '_int64'

Please tell me how to fix this error.

Code

#include <string.h>
#include <jni.h>

jstring Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction(
        JNIEnv* env, jobject javaThis) {
    return (*env)->NewStringUTF(env, "Hello from native code!");
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

the following should help alleviate this issue:

Building JNI-based Java Applications under Linux and Cygwin

Java mods for Cygwin Builds

Under Cygwin, the JNI (Java Native Interface) library we created called JNILibrary doesn’t build because gcc doesn’t know about the type “__int64″. You’ll know you hit the problem if you see something like this:

Building JNILibrary class and header…. In file included from /cygdrive/c/j2sdk1.4.2_12/include/jni.h:27, from JNICrunch-common.h:25,
from JNICrunchHWInfo.c:31:
/cygdrive/c/j2sdk1.4.2_12/include/win32/jni_md.h:16: error: parse error before “jlong”. /cygdrive/c/j2sdk1.4.2_12/include/win32/jni_md.h:16: warning: data definition has no type or storage class

If you do hit this, then you need to edit /cygdrive/c/j2sdk1.4.2_12/include/win32/jni_md.h and change these lines:

typedef long jint;
typedef __int64 jlong;
typedef signed char jbyte;

to:

typedef long jint;
#ifdef __GNUC__
typedef long long jlong;
#else
typedef __int64 jlong;
#endif
typedef signed char jbyte;

You could also try the following:

  1. Add #include <stdint.h> before #include <jni.h> in the header... or

  2. Add the java compiler flag: -D__int64=int64_t


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...