JNI静态库无法链接

时间:2011-03-09 23:47:07

标签: android java-native-interface android-ndk

我正在尝试调试在构建应用程序的C ++端时遇到的一些链接错误。 Android.mk如下所示:

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-build表单。输出如下:

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?

1 个答案:

答案 0 :(得分: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)