我用成功將編譯庫LibXtract編譯爲共享庫libxtract.so並且想用在第二個工程中。Android下的鏈接共享庫NDK
在提到項目中,我嘗試編譯它簡單的功能:
#include <com_androidnative1_NativeClass.h>
#include <android/log.h>
#include "libxtract.h"
JNIEXPORT void JNICALL Java_com_androidnative1_NativeClass_showText
(JNIEnv *env, jclass clazz)
{
float mean = 0, vector[] = {.1, .2, .3, .4, -.5, -.4, -.3, -.2, -.1}, spectrum[10];
int n, N = 9;
float argf[4];
argf[0] = 8000.f;
argf[1] = XTRACT_MAGNITUDE_SPECTRUM;
argf[2] = 0.f;
argf[3] = 0.f;
xtract[XTRACT_MEAN]((void *)&vector, N, 0, (void *)&mean);
__android_log_print(ANDROID_LOG_DEBUG, "LIbXtract", "Button pushe2");
}
我有扁平的結構:
- JNI/com_androidnative1_NativeClass.c
- JNI/com_androidnative1_NativeClass.hjni/libxtract。 h
- jni/other * .h文件來自libxtract界面
- jni/A ndroid.mk
- JNI/Applicatoin.mk
庫libxtract.so我把mainproject/lib文件夾
我Android.mk文件看起來像:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := com_androidnative1_NativeClass.c
LOCAL_MODULE := com_androidnative1_NativeClass
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/
LOCAL_LDLIBS += -llog
LOCAL_SHARE_LIBRARIES := libxtract
NDK_MODULE_PATH += $(LOCAL_PATH)/../lib/
include $(BUILD_SHARED_LIBRARY)
,我仍然出現錯誤:
Compile thumb : com_androidnative1_NativeClass <= com_androidnative1_NativeClass.c
SharedLibrary : libcom_androidnative1_NativeClass.so./obj/local/armeabi/objs/com_androidnative1_NativeClass/com_androidnative1_Nativ eClass.o: In function `Java_com_androidnative1_NativeClass_showText':
/home/jack/Projects/AndroidNative1/jni/com_androidnative1_NativeClass.c:20: undefined reference to `xtract'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libcom_androidnative1_NativeClass.so] Error 1
代碼來自LibXtract的示例和C++ com沒有問題的堆,任何想法?
您具體是如何編譯libxtract.so?你爲什麼不把它的編譯添加到同一個Android.mk文件中,這樣兩個共享庫可以同時創建? –
我通過採用這種解決方案編譯它[鏈接](http://stackoverflow.com/a/7308682/1409501)我只是添加碎紙庫,以保持它簡單 – Jack
這個答案聽起來像解決您的問題。 http://stackoverflow.com/questions/10593987/android-ndk-linking/10615769#10615769 – codetiger