使用MinGW64的JAWT应用程序无法运行

时间:2012-08-30 17:52:52

标签: java java-native-interface windows-7-x64 mingw-w64 jawt

尝试运行JAWT / JNI应用程序。

我在Windows 7 x64上使用jdk1.6.0_31和MinGW64。编译进展顺利,但仍然无法运行应用程序。在添加JAWT_GetAWT()函数之前没有问题。

问题在于我是C / C ++编程语言的新手。

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);
    }
}

生成 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
}
来自here

GCC编译命令行

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  

应用程序提供了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.

请帮忙!

1 个答案:

答案 0 :(得分:0)

您可以试试这里提出的解决方案:https://github.com/mikiobraun/jblas/issues/9

(他们也使用MinGW64,这就是为什么我认为这也可以解决你的问题。)