Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!");
}
like image 526
user4440171 Avatar asked Jan 11 '15 20:01

user4440171


1 Answers

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

like image 196
Mr. Polywhirl Avatar answered Nov 08 '22 07:11

Mr. Polywhirl