编译环境:https://sourceforge.net/projects/orwelldevcpp/
gcc:64位
Hello.java
public class Hello
{
static
{
System.loadLibrary("Hello");
}
public static native void sayHello();
@SuppressWarnings("static-access")
public static void main(String[] args)
{
new Hello().sayHello();
}
}
命令行命令
javac Hello.java
javah Hello
hello.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Hello */
#ifndef _Included_Hello
#define _Included_Hello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Hello
* Method: sayHello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Hello_sayHello
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
hello.c
#include "Hello.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_HelloNative_sayHello()
{
printf("Hello,zn");
}
进行编译,生成dll文件
注:dll文件需要是64位的
运行hello.class
结果如下:
结果
网友评论