简体   繁体   English

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

[英]JAWT Application using MinGW64 doesn't run

Trying to run JAWT/JNI application. 尝试运行JAWT / JNI应用程序。

I'm using jdk1.6.0_31 and MinGW64 on Windows 7 x64. 我在Windows 7 x64上使用jdk1.6.0_31和MinGW64 Compilation goes smoothly, but still couldn't run application. 编译过程很顺利,但是仍然无法运行应用程序。 There is no problem till I add JAWT_GetAWT() function. 在添加JAWT_GetAWT()函数之前没有问题。

The problem is that I'm new at C/C++ programming languages. 问题是我是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);
    }
}

Generated Native.h 生成的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编译命令行

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: 应用程序给出了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 您可以尝试这里提出的解决方案: https : //github.com/mikiobraun/jblas/issues/9

(They are also using MinGW64, that's why I think this might solve your problem too.) (他们也使用MinGW64,这就是为什么我认为这也可以解决您的问题。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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