2011-03-09 121 views
1

我正在嘗試調試構建應用程序的C++端時出現的一些鏈接錯誤。 Android.mk看起來如下:JNI靜態庫無法鏈接

LOCAL_PATH := $(call my-dir) 

include $(CLEAR_VARS) 

LOCAL_MODULE := GLES 
LOCAL_SRC_FILES := ModelGLES.cpp RendererGLES.cpp 
LOCAL_LDLIBS := -llog -lGLESv1_CM 
LOCAL_LDFLAGS := -Wl,-Map,$(LOCAL_MODULE).map 

include $(BUILD_SHARED_LIBRARY) 

include $(CLEAR_VARS) 

LOCAL_MODULE := SndSys 
LOCAL_SRC_FILES := SndSys.cpp libaudio_wrapper.cpp 
LOCAL_STATIC_LIBRARIES := libaudio_ARM_NDK 
LOCAL_LDLIBS := -llog 
LOCAL_LDFLAGS := -Wl,-Map,$(LOCAL_MODULE).map 
LOCAL_C_INCLUDES := $(LOCAL_PATH) 

include $(BUILD_SHARED_LIBRARY) 

我得到的錯誤是libaudio_wrapper。鏈接器無法改變libaudio_ARM_NDK中的符號。文件夾結構如下所示:

應用程序\ JNI \ SndSys.cpp libaudio_wrapper.cpp Android.mk libaudio_ARM_NDK.a

我打電話JNI的文件夾內NDK建造形式。輸出如下:

Gdbserver  : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver 
Gdbsetup  : libs/armeabi/gdb.setup 
Compile++ thumb : GLES <= ModelGLES.cpp 
Compile++ thumb : GLES <= RendererGLES.cpp 
SharedLibrary : libGLES.so 
Install  : libGLES.so => libs/armeabi/libGLES.so 
Compile++ thumb : SndSys <= SndSys.cpp 
Compile++ thumb : SndSys <= libaudio_wrapper.cpp 
SharedLibrary : libSndSys.so 
/Users/bob/Desktop/Root/Relaxation/obj/local/armeabi/objs-debug/SndSys/libaudio_wrapper.o: In function `audioInit(int, int)': 
/Users/bob/Desktop/Root/Relaxation/jni/libaudio_wrapper.cpp:37: undefined reference to `GetAudioChannelSize' 
/Users/bob/Desktop/Root/Relaxation/jni/libaudio_wrapper.cpp:38: undefined reference to `GetAudioInitControlSize' 

是否有一種簡單的方法來查看鏈接器是否正在查找我的庫?或者讓命令行調用gcc或ld?

回答

5

問題是我升級到了ndk-r5。構建Prebuilt庫的一些規則已經改變。每個預建庫都需要爲其預留自己的模塊。 Android.ml的下半部分應該看起來像這樣...

include $(CLEAR_VARS) 

LOCAL_MODULE := audiolib 
LOCAL_SRC_FILES := libaudio_ARM_NDK.a 

include $(PREBUILT_STATIC_LIBRARY) 


include $(CLEAR_VARS) 

LOCAL_MODULE := SndSys 
LOCAL_SRC_FILES := SndSys.cpp libaduio_wrapper.cpp 
LOCAL_STATIC_LIBRARIES := audiolib 
LOCAL_LDLIBS := -llog 

include $(BUILD_SHARED_LIBRARY)