JNI无法编译动态库

时间:2016-12-12 13:06:53

标签: java

我正在创建一个c ++动态库,用于java中的本机类 我使用javah.exe为该类生成了一个头文件,并为它创建了c接口类,但是当我尝试编译文件或构建项目时,我收到以下错误

/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:339:72: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:416:20: error: expected identifier before '*' token
     jlong (JNICALL *CallNonvirtualLongMethod)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:416:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallNonvirtualLongMethod)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:417:71: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
       (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
                                                                       ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:417:71: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:418:20: error: expected identifier before '*' token
     jlong (JNICALL *CallNonvirtualLongMethodV)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:418:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallNonvirtualLongMethodV)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:420:20: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
        va_list args);
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:420:20: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:421:20: error: expected identifier before '*' token
     jlong (JNICALL *CallNonvirtualLongMethodA)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:421:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallNonvirtualLongMethodA)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:423:26: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
        const jvalue *args);
                          ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:423:26: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:467:20: error: expected identifier before '*' token
     jlong (JNICALL *GetLongField)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:467:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *GetLongField)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:468:50: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
       (JNIEnv *env, jobject obj, jfieldID fieldID);
                                                  ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:468:50: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:487:52: error: 'jlong' has not been declared
       (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val);
                                                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:538:20: error: expected identifier before '*' token
     jlong (JNICALL *CallStaticLongMethod)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:538:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallStaticLongMethod)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:539:58: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
       (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
                                                          ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:539:58: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:540:20: error: expected identifier before '*' token
     jlong (JNICALL *CallStaticLongMethodV)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:540:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallStaticLongMethodV)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:541:67: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
       (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
                                                                   ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:541:67: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:542:20: error: expected identifier before '*' token
     jlong (JNICALL *CallStaticLongMethodA)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:542:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallStaticLongMethodA)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:543:73: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
       (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
                                                                         ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:543:73: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:580:20: error: expected identifier before '*' token
     jlong (JNICALL *GetStaticLongField)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:580:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *GetStaticLongField)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:581:51: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
       (JNIEnv *env, jclass clazz, jfieldID fieldID);
                                                   ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:581:51: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:600:53: error: 'jlong' has not been declared
       (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value);
                                                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:662:5: error: 'jlong' does not name a type
     jlong * (JNICALL *GetLongArrayElements)
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:680:39: error: 'jlong' has not been declared
       (JNIEnv *env, jlongArray array, jlong *elems, jint mode);
                                       ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:697:63: error: 'jlong' has not been declared
       (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
                                                               ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:714:69: error: 'jlong' does not name a type
       (JNIEnv *env, jlongArray array, jsize start, jsize len, const jlong *buf);
                                                                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:758:37: error: 'jlong' has not been declared
        (JNIEnv* env, void* address, jlong capacity);
                                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:761:20: error: expected identifier before '*' token
     jlong (JNICALL *GetDirectBufferCapacity)
                    ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:761:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *GetDirectBufferCapacity)
                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:762:33: error: ISO C++ forbids declaration of 'jlong' with no type [-fpermissive]
        (JNIEnv* env, jobject buf);
                                 ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:762:33: error: 'jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1000:5: error: 'jlong' does not name a type
     jlong CallLongMethod(jobject obj, jmethodID methodID, ...) {
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1008:5: error: 'jlong' does not name a type
     jlong CallLongMethodV(jobject obj, jmethodID methodID,
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1012:5: error: 'jlong' does not name a type
     jlong CallLongMethodA(jobject obj, jmethodID methodID,
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1192:5: error: 'jlong' does not name a type
     jlong CallNonvirtualLongMethod(jobject obj, jclass clazz,
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1202:5: error: 'jlong' does not name a type
     jlong CallNonvirtualLongMethodV(jobject obj, jclass clazz,
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1207:5: error: 'jlong' does not name a type
     jlong CallNonvirtualLongMethodA(jobject obj, jclass clazz,
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1300:5: error: 'jlong' does not name a type
     jlong GetLongField(jobject obj, jfieldID fieldID) {
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1334:23: error: 'jlong' has not been declared
                       jlong val) {
                       ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1459:5: error: 'jlong' does not name a type
     jlong CallStaticLongMethod(jclass clazz,
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1468:5: error: 'jlong' does not name a type
     jlong CallStaticLongMethodV(jclass clazz,
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1472:5: error: 'jlong' does not name a type
     jlong CallStaticLongMethodA(jclass clazz,
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1550:5: error: 'jlong' does not name a type
     jlong GetStaticLongField(jclass clazz, jfieldID fieldID) {
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1585:25: error: 'jlong' has not been declared
                         jlong value) {
                         ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1679:5: error: 'jlong' does not name a type
     jlong * GetLongArrayElements(jlongArray array, jboolean *isCopy) {
     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1715:35: error: 'jlong' has not been declared
                                   jlong *elems,
                                   ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1751:53: error: 'jlong' has not been declared
                             jsize start, jsize len, jlong *buf) {
                                                     ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1784:35: error: 'jlong' does not name a type
                             const jlong *buf) {
                                   ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1847:48: error: 'jlong' has not been declared
     jobject NewDirectByteBuffer(void* address, jlong capacity) {
                                                ^
/cygdrive/c/Program Files/Java/jdk1.7.0_25/include/jni.h:1853:5: error: 'jlong' does not name a type
     jlong GetDirectBufferCapacity(jobject buf) {
     ^
nbproject/Makefile-Debug.mk:67: recipe for target 'build/Debug/Cygwin_1-Windows/newfile.o' failed
make[2]: *** [build/Debug/Cygwin_1-Windows/newfile.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/Prashanth/Documents/NetBeansProjects/Native_DLL'
nbproject/Makefile-Debug.mk:60: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/Prashanth/Documents/NetBeansProjects/Native_DLL'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2

尚未定义某些数据类型,如jlong​​,int64,int32 我正在使用netbeans来编译这个库 我陷入了困境 plzz帮助任何人?

1 个答案:

答案 0 :(得分:1)

对于任何偶然发现此问题的人,根本问题是JNICALL未定义。有关更多信息,请参见this answer

为我解决了这一问题,方法是将#define JNICALL __stdcall添加到jni_md.h文件中,该文件可以在$JAVA_HOME/include/<platform>中找到。 (对我来说, platform 是win32)