Skip to content

Instantly share code, notes, and snippets.

@fantasticmao
Created June 5, 2020 07:39
Show Gist options
  • Save fantasticmao/f6147a60f1b35b4442ca29e73b6627f8 to your computer and use it in GitHub Desktop.
Save fantasticmao/f6147a60f1b35b4442ca29e73b6627f8 to your computer and use it in GitHub Desktop.
Java JNI 简单实践
#include <jni.h>
#include "cn_fantasticmao_jni_SumNative.h"
/*
* Class: cn_fantasticmao_jni_SumNative
* Method: sum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_cn_fantasticmao_jni_SumNative_sum
(JNIEnv *env, jobject obj, jint a, jint b)
{
return a + b;
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class cn_fantasticmao_jni_SumNative */
#ifndef _Included_cn_fantasticmao_jni_SumNative
#define _Included_cn_fantasticmao_jni_SumNative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: cn_fantasticmao_jni_SumNative
* Method: sum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_cn_fantasticmao_jni_SumNative_sum
(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
package cn.fantasticmao.jni;
public class SumNative {
static {
System.loadLibrary("sum");
}
public native int sum(int a, int b);
public static void main(String[] args) {
int value = new SumNative().sum(1, 2);
System.out.printf("1 + 2 = %d%n", value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment