RPIのセンスハットとJavaのものをインターフェースするためにネイティブコードを使用しています。私はJavaでスタブを書いて、それをコンパイルしてからjavahを使ってヘッダファイルを抽出しました。単純なchar配列を返す文字列に変換するために、Cでメソッドを作成しました。私はそれをコンパイルすることはできないようです。 のJava:JNI Cの互換性のないポインタ型をコンパイルできません
/**
* NativeTest - PACKAGE_NAME
* Created by matthew on 21/07/16.
*/
class SenseHat
{
static {
System.loadLibrary("SenseHat");
}
public native String getTemperature();
public native String getHumidity();
public native String getOrientation();
}
ヘッダファイル:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class SenseHat */
#ifndef _Included_SenseHat
#define _Included_SenseHat
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: SenseHat
* Method: getTemperature
* Signature:()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_SenseHat_getTemperature
(JNIEnv *, jobject);
/*
* Class: SenseHat
* Method: getHumidity
* Signature:()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_SenseHat_getHumidity
(JNIEnv *, jobject);
/*
* Class: SenseHat
* Method: getOrientation
* Signature:()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_SenseHat_getOrientation
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
Cファイル:
#include <jni.h>
#include <stdio.h>
#include "SenseHat.h"
JNIEXPORT jstring JNICALL Java_SenseHat_getTemperature(JNIEnv *env, jobject thisObj) {
char done[] = "temperature";
jstring answer;
/* Make a new String based on done, then free done. */
answer = (*env)->NewStringUTF(env,&done);
free(done);
return answer;
}
JNIEXPORT jstring JNICALL Java_SenseHat_getHumidity(JNIEnv *env, jobject thisObj) {
char done[9] = "humidity";
jstring answer;
/* Make a new String based on done, then free done. */
answer = (*env)->NewStringUTF(env,&done);
free(done);
return answer;
}
JNIEXPORT jstring JNICALL Java_SenseHat_getOrientation(JNIEnv *env, jobject thisObj) {
char done[12] = "orientation";
jstring answer;
/* Make a new String based on done, then free done. */
answer = (*env)->NewStringUTF(env,&done);
free(done);
return answer;
}
私は、次のコマンドを使用して、それをコンパイルしています:
gcc -I /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/ -I /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/linux/ -shared -o libSenseHat.so SenseHat.c
コンパイラ出力を提供できますか? – Sergio