1

I'm creating an c++ dynamic library to use in an native class in java I have generated an header file for that class using javah.exe and have created the c interface class for it,but when I try to comile the file or build the project I get the following error

/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

some data types such as jlong,int64,int32 have not been defined I'm using netbeans to compile this library I'm stuck at this point plzz help anyone?

Grim
  • 1,938
  • 10
  • 56
  • 123
Sync it
  • 1,180
  • 2
  • 11
  • 29

1 Answers1

1

For anyone else who stumbles upon this, the root problem is that JNICALL is not defined. See this answer for some more info.

This was fixed for me by adding #define JNICALL __stdcall to the jni_md.h file, which can be found in $JAVA_HOME/include/<platform>. (for me platform was win32)

RobC
  • 22,977
  • 20
  • 73
  • 80
Zac
  • 88
  • 1
  • 6
  • It was a long time ago and ur mostly right. I fixed my errors by compiling my native class file through javah.exe[bin directory of my jdk] which gave me an correctly compiled c header file which I then added to visual studio 2017 and built my dll file there. I gave up on cygwin a very long time ago – Sync it Nov 02 '19 at 03:28