473,574 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JNI Netbeans and Cygwin Compile problem

188 New Member
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 6645
188 New Member
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 `getAwtLockFunc tions':

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
1 New Member
I'm having the same undefined reference problem. How did you solve it ?

Any help highly appreciated
Jun 7 '09 #3

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

Similar topics

by: Zhuanshi He | last post by:
I try to compile ScientificPython-2.4.9 (http://starship.python.net/~hinsen/ScientificPython/) under Windows XP cygwin environment using python 2.3.3 ,and gcc (GCC) 3.3.3 (cygwin special). The information shows as follows: ---------------------------------------------------------- Using netCDF installation in /usr/local running build
by: goberle | last post by:
I have installed the Cygwin package under WinXP. I am trying to insure that I have a reasonable development environment, and that things are working properly, by trying to compile and run the following classic program. $ cat hellow.cpp #include <iostream> int main (int argc, char *argv) { cout << "Hello, world" << endl;
by: Norm Wong | last post by:
If anyone is interested in using db2uext2 with Cygwin gcc compiler on Windows, I've modified the IBM provided sample with the attached file. There are two main modifications. The mkdir command is the POSIX compliant version as opposed to the MicroSoft C compiler. The second parameter to mkdir is the file mode. In this case, I've made the...
by: Abby | last post by:
I'm now using Cygwin as my compiler for C code. I use Dev-c++ as my editor. The reason why I chose Cygwin compiler instead of the compiler that came with Dev-C++ is that I believe it uses the same environment as in Linux, so that I don't have to write different sourcecode for both OS. Eventhough, I don't understand about Linux much, and I'm...
by: JS | last post by:
I use winXP and have installed Cygwin. I use Dev-C++ and the Cygwin compiler, but for some reason I can't compile this code: #include <setjmp.h> #include <stdio.h> #include <stdlib.h> typedef int othread_t;
by: 63q2o4i02 | last post by:
Hi, I'm using python 2.4 and windows XP. I have two packages in the windows version of python in site-packages. They are PyVisa and ctypes, and both live in c:\python24\lib\site-packages I'd like to move these to the cygwin version of python on the same system. I tried copying the PyVisa and ctypes directorices (including
by: Heritage | last post by:
I have in association with the non-profit organisation World Heritage been trying to compile an opensource project under the CygWin environment. The project utilizes a c++ and java integration development scheme. I have tried for some time now, to set up the CygWin environment so that I could compile the sourcecode, but to no avail. (Its meant...
by: Vinay | last post by:
Hello, I have to compile the ICU 3.4 Using Intel C++ Compiler 9.0 with Cygwin on Windows Server 2003 (IA 64 machine). But I am facing a lot of difficulties. 1. I tried to compile a simple c program //Program.c #include <stdio.h>
by: dot | last post by:
I spent a few headache filled days trying to use GMP on windows (XP pro) I finally got it to work and since I found little help on the Web I thought someone might find what i did useful. Creating an environment suitable for GMP programming. 1) Create 'cygwin' environment (see below) 2)add GMP to the cygwin directory (see below)
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.