简体   繁体   中英

JAWT Application using MinGW64 doesn't run

Trying to run JAWT/JNI application.

I'm using jdk1.6.0_31 and MinGW64 on Windows 7 x64. Compilation goes smoothly, but still couldn't run application. There is no problem till I add JAWT_GetAWT() function.

The problem is that I'm new at C/C++ programming languages.

Native.java

import java.awt.Component;
import javax.swing.JFrame;

public class Native{

    static {
        System.loadLibrary("native");
    }

    public static native boolean getBoolean(Component component);

    public static void main(String args[]){
        JFrame frame = new JFrame("test viewport");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.pack();

        getBoolean(frame);
    }
}

Generated Native.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Native */

#ifndef _Included_Native
#define _Included_Native
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Native
 * Method:    getBoolean
 * Signature: (Ljava/awt/Component;)Z
 */
JNIEXPORT jboolean JNICALL Java_Native_getBoolean
  (JNIEnv *, jclass, jobject);

#ifdef __cplusplus
}
#endif
#endif

Native.c

#include <jni.h>
#include <jawt_md.h>
#include <jawt.h>
#include "Native.h"

JNIEXPORT jboolean JNICALL Java_Native_getBoolean(JNIEnv *env, jclass class, jobject component){
    JAWT awt;
    awt.version = JAWT_VERSION_1_4;

    return JAWT_GetAWT(env, &awt);//can't run after I add this function
}

GCC compilation command line from here

gcc -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -Id:/devtools/java/jdk1.6.0_31/include -Id:/devtools/java/jdk1.6.0_31/include/win32 -LD:/devtools/java/jdk1.6.0_31/jre/bin -ljawt -shared Native.c -o native.dll  

Application gives java.lang.UnsatisfiedLinkError:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\t.key\Desktop\Native\native.dll: Can't find dependent libraries
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at Native.<clinit>(Native.java:7)
Could not find the main class: Native.  Program will exit.

Please help!

You might give a try to the solutions proposed here: https://github.com/mikiobraun/jblas/issues/9

(They are also using MinGW64, that's why I think this might solve your problem too.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM