471,853 Members | 1,038 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

JNI Netbeans and Cygwin Compile problem

188 100+
Hi All,

Am working on a Java application in which I have to use the JNI to Interface with some native code for both windows and unix. Am using netbeans IDE with the C/C++ pack installed. Am also using Cygwin as my compiler (gcc), this is ostensibly because I hope this compiler will also compile the unix native libraries since I don't have a Linux installation. (I am working on a personal project from the office and can't get linux installed).

First question will it be possible to get native linux libs from Cygwin?

I tried doing a small test using the windows function FindWindow() and I am not able to build it. gcc complains about the jlong type defined by the JNI headers.

Here is the code followed by the netbeans output.

Help is greatly appreciated.

The Java class

Expand|Select|Wrap|Line Numbers
  2. public class OslibClass {
  3.     static{
  4.         System.loadLibrary("libOsibClass");
  5.     }
  7.     public void OslibClass(){
  9.     }
  10.     private static native long getWindowHandle();
  12. }
Native code...

Expand|Select|Wrap|Line Numbers
  2. #include <OslibClass.h>
  3. #include <windows.h>
  6. JNIEXPORT jlong JNICALL Java_org_OslibClass_getWindowHandle
  7. (JNIEnv *, jclass){
  8.     jlong handle;
  9.     HWND hwnd = FindWindow("SunAwtFrame","GetHandle - NetBeans IDE 6.1");
  10.     handle = hwnd;
  11.     return handle;
  12. }
Netbeans Output...
Expand|Select|Wrap|Line Numbers
  1. Running "rm -rf build/Debug/Cygwin-Windows/src/OslibClass.o" in C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\GetHandle
  4. Clean successful. Exit value 0.
  6. Running "C:\cygwin\bin\make.exe -f nbproject/Makefile-Debug.mk build/Debug/Cygwin-Windows/src/OslibClass.o" in C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\GetHandle
  8. mkdir -p build/Debug/Cygwin-Windows/src
  9. gcc.exe    -c -g -IC\:/Program\ Files/Java/jdk1.6.0_07/include/win32 -IC\:/Program\ Files/Java/jdk1.6.0_07/include -I. -fPIC  -o build/Debug/Cygwin-Windows/src/OslibClass.o src/OslibClass.c
  10. src/OslibClass.c:1: warning: -fPIC ignored for target (all code is position independent)
  11. In file included from C:/Program Files/Java/jdk1.6.0_07/include/jni.h:27,
  12.                  from ./OslibClass.h:2,
  13.                  from src/OslibClass.c:1:
  14. C:/Program Files/Java/jdk1.6.0_07/include/win32/jni_md.h:16: error: parse error before "jlong"
  15. C:/Program Files/Java/jdk1.6.0_07/include/win32/jni_md.h:16: warning: data definition has no type or storage class
  16. In file included from ./OslibClass.h:2,
  17.                  from src/OslibClass.c:1:
  18. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:108: error: parse error before "jlong"
  19. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:108: warning: no semicolon at end of struct or union
  20. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:112: error: parse error before '}' token
  21. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:112: warning: data definition has no type or storage class
  22. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:264: error: parse error before '*' token
  23. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:279: error: parse error before '*' token
  24. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:286: error: parse error before '*' token
  25. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:293: error: parse error before '*' token
  26. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:300: error: parse error before '*' token
  27. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:307: error: parse error before '*' token
  28. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:314: error: parse error before '*' token
  29. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:316: warning: no semicolon at end of struct or union
  30. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:318: error: parse error before '*' token
  31. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:319: error: `jlong' declared as function returning a function
  32. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:319: error: 'jlong' redeclared as different kind of symbol
  33. C:/Program Files/Java/jdk1.6.0_07/include/win32/jni_md.h:16: error: previous declaration of 'jlong' was here
  34. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:319: warning: data definition has no type or storage class
  35. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:320: error: parse error before '*' token
  36. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:321: error: parse error before '*' token
  37. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:321: error: `jlong' declared as function returning a function
  38. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:321: warning: data definition has no type or storage class
  39. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:328: error: parse error before '*' token
  40. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:335: error: parse error before '*' token
  41. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:342: error: parse error before '*' token
  42. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:351: error: parse error before '*' token
  43. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:360: error: parse error before '*' token
  44. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:369: error: parse error before '*' token
  45. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:378: error: parse error before '*' token
  46. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:387: error: parse error before '*' token
  47. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:396: error: parse error before '*' token
  48. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:398: error: parse error before '*' token
  49. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:399: error: `jlong' declared as function returning a function
  50. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:399: warning: data definition has no type or storage class
  51. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:400: error: parse error before '*' token
  52. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:402: error: `jlong' declared as function returning a function
  53. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:402: warning: data definition has no type or storage class
  54. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:403: error: parse error before '*' token
  55. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:405: error: parse error before '*' token
  56. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:405: error: `jlong' declared as function returning a function
  57. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:405: warning: data definition has no type or storage class
  58. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:414: error: parse error before '*' token
  59. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:423: error: parse error before '*' token
  60. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:432: error: parse error before '*' token
  61. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:449: error: parse error before '*' token
  62. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:450: error: `jlong' declared as function returning a function
  63. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:450: warning: data definition has no type or storage class
  64. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:469: error: parse error before "jlong"
  65. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:483: error: parse error before '*' token
  66. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:490: error: parse error before '*' token
  67. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:497: error: parse error before '*' token
  68. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:504: error: parse error before '*' token
  69. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:511: error: parse error before '*' token
  70. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:518: error: parse error before '*' token
  71. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:520: error: parse error before '*' token
  72. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:521: error: `jlong' declared as function returning a function
  73. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:521: warning: data definition has no type or storage class
  74. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:522: error: parse error before '*' token
  75. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:523: error: `jlong' declared as function returning a function
  76. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:523: warning: data definition has no type or storage class
  77. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:524: error: parse error before '*' token
  78. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:525: error: parse error before '*' token
  79. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:525: error: `jlong' declared as function returning a function
  80. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:525: warning: data definition has no type or storage class
  81. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:532: error: parse error before '*' token
  82. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:539: error: parse error before '*' token
  83. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:546: error: parse error before '*' token
  84. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:562: error: parse error before '*' token
  85. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:563: error: `jlong' declared as function returning a function
  86. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:563: warning: data definition has no type or storage class
  87. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:582: error: parse error before "jlong"
  88. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:644: error: parse error before '*' token
  89. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:645: warning: data definition has no type or storage class
  90. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:662: error: parse error before "jlong"
  91. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:679: error: parse error before "jlong"
  92. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:696: error: parse error before '*' token
  93. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:740: error: parse error before "jlong"
  94. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:743: error: parse error before '*' token
  95. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:744: error: `jlong' declared as function returning a function
  96. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:744: warning: data definition has no type or storage class
  97. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:750: error: parse error before '}' token
  98. In file included from src/OslibClass.c:1:
  99. ./OslibClass.h:15: warning: `__stdcall__' attribute only applies to function types
  100. ./OslibClass.h:15: error: 'jlong' redeclared as different kind of symbol
  101. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:744: error: previous declaration of 'jlong' was here
  102. ./OslibClass.h:15: error: 'jlong' redeclared as different kind of symbol
  103. C:/Program Files/Java/jdk1.6.0_07/include/jni.h:744: error: previous declaration of 'jlong' was here
  104. ./OslibClass.h:15: error: parse error before "Java_org_OslibClass_getWindowHandle"
  105. src/OslibClass.c:5: warning: `__stdcall__' attribute only applies to function types
  106. src/OslibClass.c:5: error: parse error before "Java_org_OslibClass_getWindowHandle"
  107. src/OslibClass.c:8: error: initializer element is not constant
  108. src/OslibClass.c:9: warning: initialization makes integer from pointer without a cast
  109. src/OslibClass.c:9: error: initializer element is not constant
  110. src/OslibClass.c:9: warning: data definition has no type or storage class
  111. src/OslibClass.c:10: error: parse error before "return"
  112. make: *** [build/Debug/Cygwin-Windows/src/OslibClass.o] Error 1
  114. Build failed. Exit value 2.
Sep 17 '08 #1
2 6496
188 100+
Seems I figured it out somehow.
In netbeans I was pointing the include path for the JNI headers to where my JDK windows installer had installed them. i.e ..Program files\\java..... I found out though that cygwin comes with it's own java compiler (or is it just headers??) and netbeans knows where to find them. So I removed my include from the nebeans settings and voila!!

Din't get to figure out what was really happening. Perherps someone can tell us.
Now, I kind of want to build a native library (.so) but when I trie it, the linker doesn't seem to find some references. Example I keep getting..

undefined reference to `_dlopen'
undefined reference to `___getreent'
undefined reference to `_dlerror'
undefined reference to `___getreent'
In function `getAwtLockFunctions':

and so on for very many functions.

Even if I put the directory with these .a files explicitly in the link properties in netbeans, I still get the same errors.




Sep 18 '08 #2
I'm having the same undefined reference problem. How did you solve it ?

Any help highly appreciated
Jun 7 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by goberle | last post: by
reply views Thread by Norm Wong | last post: by
12 posts views Thread by JS | last post: by
2 posts views Thread by 63q2o4i02 | last post: by
4 posts views Thread by Heritage | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.