我想创建一个共享库,因为 JNI 需要它。
我有两个文件
压电扬声器.c
#include "PiezoSpeaker.h"
#include <stdio.h>
#include <string.h>
#include <wiringPi.h>
#include <softTone.h>
JNIEXPORT void JNICALL Java_PiezoSpeaker_tone__I
(JNIEnv *env, jobject jobject, jint khz) {
wiringPiSetup();
softToneCreate(29);
softToneWrite (29, khz);
}
JNIEXPORT void JNICALL Java_PiezoSpeaker_tone__II
(JNIEnv *env, jobject jobject, jint khz, jint duration) {
}
和
压电扬声器.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class PiezoSpeaker */
#ifndef _Included_PiezoSpeaker
#define _Included_PiezoSpeaker
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: PiezoSpeaker
* Method: tone
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_PiezoSpeaker_tone__I
(JNIEnv *, jobject, jint);
/*
* Class: PiezoSpeaker
* Method: tone
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_PiezoSpeaker_tone__II
(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
我用 gcc 编译这个
gcc -c -fPIC -I"/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/" -I"/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/linux" -IwiringPi -Ipthread PiezoSpeaker.c
gcc -shared -o share.so PiezoSpeaker.o
我成为错误,符号未定义。gcc 命令是错误的,因为它不包含wiringPi 库。如何链接包含 WiringPi Lib 的库?