0

my program code

#include "HelloWorld.h"
#include <stdio.h>
#include <windows.h>
#include <signal.h>
using namespace std;
JNIEnv *cur_env; /* pointer to native method interface */
void registerWndProc();
JNIEXPORT void JNICALL Java_HelloWorld_print
(JNIEnv *env, jobject){
cur_env = env; /* Creates window & enters message loop */
registerWndProc();
}
void calljvm() {
JavaVM *jvm;
cur_env->GetJavaVM(&jvm);
jint AttachCurrentThread = (*jvm).AttachCurrentThread((void **)(&cur_env),NULL);
jclass cls=cur_env->FindClass("helloworld/HelloWorld");
jmethodID mid=cur_env->GetStaticMethodID(cls,"callback","()V");      
(*cur_env).CallStaticVoidMethod(cls, mid);
(*jvm).DetachCurrentThread();
} 
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam,LPARAM lParam)
{
switch(msg) {
    case WM_ENDSESSION :
        calljvm();
    break;
    default:
    break;
}

return DefWindowProc(hwnd, msg, wParam, lParam);
}
void registerWndProc() {
HINSTANCE h2 = GetModuleHandle(NULL); 
static char szAppName[] = "winhello";
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = h2;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL; 
/* Register a new window class with Windows */
if (!RegisterClassEx(&wndclass)) {
    MessageBox(NULL, TEXT("Registering class failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
    return;
} 
/* Create a window based on our new class */
HWND hwnd; hwnd = CreateWindow(szAppName, "Hello, world!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, h2, NULL); 
/* CreateWindow failed? */
if( !hwnd ) {
    MessageBox(NULL, TEXT("Window creation failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK);
    return;
} 
/* Show and update our window */
ShowWindow(hwnd, 0); /* 0 = SW_HIDE */
UpdateWindow(hwnd); MSG msg;
while (GetMessage(&msg, NULL, 0, 0) ) {
    TranslateMessage(&msg); /* for certain keyboard messages */
    DispatchMessage(&msg); /* send message to WndProc */
 }
} 

when i compile it in netbean compiled faild

cd 'C:\Users\ma\Documents\NetBeansProjects\HelloWorld'
C:\cygwin64\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/ma/Documents/NetBeansProjects/HelloWorld'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_1-Windows/libHelloWorld.dll
make[2]: Entering directory '/cygdrive/c/Users/ma/Documents/NetBeansProjects/HelloWorld'
mkdir -p build/Debug/Cygwin_1-Windows
rm -f "build/Debug/Cygwin_1-Windows/helloworld.o.d"
g++    -c -g -I../../../../../Program\ Files/Java/jdk1.8.0_144/include -I../../HelloWorld/src -include ../../HelloWorld/src/HelloWorld.h  -MMD -MP -MF "build/Debug/Cygwin_1-Windows/helloworld.o.d" -o build/Debug/Cygwin_1-Windows/helloworld.o helloworld.cpp
In file included from /cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:45:0,
                 from ./../../HelloWorld/src/HelloWorld.h:2,
                 from <command-line>:31:
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni_md.h:34:9: error: '__int64' does not name a type; did you mean '__int64_t'?
 typedef __int64 jlong;
         ^~~~~~~
         __int64_t
In file included from ./../../HelloWorld/src/HelloWorld.h:2:0,
                 from <command-line>:31:
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:126:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong    j;
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:334:20: error: expected identifier before '*' token
     jlong (JNICALL *CallLongMethod)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:334:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallLongMethod)
                     ^~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:335:57: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jobject obj, jmethodID methodID, ...);
                                                         ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:336:20: error: expected identifier before '*' token
     jlong (JNICALL *CallLongMethodV)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:336:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallLongMethodV)
                     ^~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:337:66: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
                                                                  ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:338:20: error: expected identifier before '*' token
     jlong (JNICALL *CallLongMethodA)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:338:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallLongMethodA)
                     ^~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:339:72: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
                                                                        ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:416:20: error: expected identifier before '*' token
     jlong (JNICALL *CallNonvirtualLongMethod)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:416:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallNonvirtualLongMethod)
                     ^~~~~~~~~~~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:417:71: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
                                                                       ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:418:20: error: expected identifier before '*' token
     jlong (JNICALL *CallNonvirtualLongMethodV)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:418:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallNonvirtualLongMethodV)
                     ^~~~~~~~~~~~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:420:20: error: 'jlong' declared as function returning a function
        va_list args);
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:421:20: error: expected identifier before '*' token
     jlong (JNICALL *CallNonvirtualLongMethodA)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:421:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallNonvirtualLongMethodA)
                     ^~~~~~~~~~~~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:423:26: error: 'jlong' declared as function returning a function
        const jvalue *args);
                          ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:467:20: error: expected identifier before '*' token
     jlong (JNICALL *GetLongField)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:467:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *GetLongField)
                     ^~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:468:50: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jobject obj, jfieldID fieldID);
                                                  ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/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.8.0_144/include/jni.h:538:20: error: expected identifier before '*' token
     jlong (JNICALL *CallStaticLongMethod)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:538:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallStaticLongMethod)
                     ^~~~~~~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:539:58: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
                                                          ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:540:20: error: expected identifier before '*' token
     jlong (JNICALL *CallStaticLongMethodV)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:540:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallStaticLongMethodV)
                     ^~~~~~~~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:541:67: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
                                                                   ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:542:20: error: expected identifier before '*' token
     jlong (JNICALL *CallStaticLongMethodA)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:542:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *CallStaticLongMethodA)
                     ^~~~~~~~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:543:73: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
                                                                         ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:580:20: error: expected identifier before '*' token
     jlong (JNICALL *GetStaticLongField)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:580:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *GetStaticLongField)
                     ^~~~~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:581:51: error: 'jlong' declared as function returning a function
       (JNIEnv *env, jclass clazz, jfieldID fieldID);
                                                   ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/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.8.0_144/include/jni.h:662:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong * (JNICALL *GetLongArrayElements)
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/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.8.0_144/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.8.0_144/include/jni.h:714:69: error: 'jlong' does not name a type; did you mean 'ulong'?
       (JNIEnv *env, jlongArray array, jsize start, jsize len, const jlong *buf);
                                                                     ^~~~~
                                                                     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:758:37: error: 'jlong' has not been declared
        (JNIEnv* env, void* address, jlong capacity);
                                     ^~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:761:20: error: expected identifier before '*' token
     jlong (JNICALL *GetDirectBufferCapacity)
                    ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:761:21: warning: '__stdcall__' attribute only applies to function types [-Wattributes]
     jlong (JNICALL *GetDirectBufferCapacity)
                     ^~~~~~~~~~~~~~~~~~~~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:762:33: error: 'jlong' declared as function returning a function
        (JNIEnv* env, jobject buf);
                                 ^
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1000:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallLongMethod(jobject obj, jmethodID methodID, ...) {
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1008:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallLongMethodV(jobject obj, jmethodID methodID,
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1012:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallLongMethodA(jobject obj, jmethodID methodID,
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1192:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallNonvirtualLongMethod(jobject obj, jclass clazz,
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1202:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallNonvirtualLongMethodV(jobject obj, jclass clazz,
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1207:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallNonvirtualLongMethodA(jobject obj, jclass clazz,
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1300:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong GetLongField(jobject obj, jfieldID fieldID) {
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1334:23: error: 'jlong' has not been declared
                       jlong val) {
                       ^~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1459:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallStaticLongMethod(jclass clazz,
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1468:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallStaticLongMethodV(jclass clazz,
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1472:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong CallStaticLongMethodA(jclass clazz,
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1550:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong GetStaticLongField(jclass clazz, jfieldID fieldID) {
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1585:25: error: 'jlong' has not been declared
                         jlong value) {
                         ^~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1679:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong * GetLongArrayElements(jlongArray array, jboolean *isCopy) {
     ^~~~~
     ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1715:35: error: 'jlong' has not been declared
                                   jlong *elems,
                                   ^~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1751:53: error: 'jlong' has not been declared
                             jsize start, jsize len, jlong *buf) {
                                                     ^~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1784:35: error: 'jlong' does not name a type; did you mean 'ulong'?
                             const jlong *buf) {
                                   ^~~~~
                                   ulong
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1847:48: error: 'jlong' has not been declared
     jobject NewDirectByteBuffer(void* address, jlong capacity) {
                                                ^~~~~
/cygdrive/c/Program Files/Java/jdk1.8.0_144/include/jni.h:1853:5: error: 'jlong' does not name a type; did you mean 'ulong'?
     jlong GetDirectBufferCapacity(jobject buf) {
     ^~~~~
     ulong
make[2]: *** [nbproject/Makefile-Debug.mk:68: build/Debug/Cygwin_1-Windows/helloworld.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/ma/Documents/NetBeansProjects/HelloWorld'
make[1]: *** [nbproject/Makefile-Debug.mk:59: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/ma/Documents/NetBeansProjects/HelloWorld'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 2s)
3
  • The 1st error looks simple. What did you try (to fix that first error)? i.e. can you clarify your problem ... (perhaps they are simple typo's) Commented Aug 8, 2018 at 23:11
  • it seems you are using the compiler for cygwin, while you should use the cross compiler cygwin2windows sourceware.org/ml/cygwin-announce/2018-07/msg00010.html Commented Aug 9, 2018 at 3:05
  • i compile my code with MinGW64 but dose not work. Commented Aug 9, 2018 at 19:35

1 Answer 1

1

i find the solution of my problem. because GCC doesn't have a __int64 built-in, and this patch basically uses "long long" instead we must edit edit the file /include/win32/jni_md.h, Where is the installation root (eg., c:/jdk1.4.2). replace the code

typedef long jint;
typedef __int64 jlong;
typedef signed char jbyte;

with

typedef long jint;
#ifdef __GNUC__
typedef long long jlong;
#else
typedef __int64 jlong;
#endif
typedef signed char jbyte;

useful source

https://gist.github.com/ssfang/e52c00cd446081cd72a982a2dd8634d4

Error when compiling in cygwin

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.