Android NDK - 包括预构建的静态库会给出未定义的引用错误

时间:2015-06-10 15:01:59

标签: makefile android-ndk shared-libraries static-libraries

我正在尝试使用预构建的静态库构建共享库。出于某种原因,构建始终无法提供undefined reference错误。如果我添加LOCAL_ALLOW_UNDEFINED_SYMBOLS := true,构建成功但共享库只有几千字节,而静态库大约是3兆字节......所以在链接静态库时似乎出了问题。我不知道它可能是什么。我只使用C ++代码。

Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := kes
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := libkes.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := PortaKES
LOCAL_SRC_FILES := PortaKES.cpp
LOCAL_STATIC_LIBARIES := kes

include $(BUILD_SHARED_LIBRARY)

Application.mk:

APP_ABI := all
APP_STL := stlport_static

JNI目录结构:

JNI folder structure

输出:

./obj/local/arm64-v8a/objs/PortaKES/PortaKES.o: In function `Java_com_kurzweil_portakes_KESFile_createPOLEFile':
C:\Users\niels.mylle\Documents\Kurzweil Mobile Android\PortaKES/jni/PortaKES.cpp:18: undefined reference to `CPoleFile::CPoleFile(char const*, bool, bool, CEncrypter*)'
./obj/local/arm64-v8a/objs/PortaKES/PortaKES.o: In function `Java_com_kurzweil_portakes_KESFile_createKSection':
C:\Users\niels.mylle\Documents\Kurzweil Mobile Android\PortaKES/jni/PortaKES.cpp:33: undefined reference to `CKSection::CKSection(char const*, CPoleFile*, CPoleLeaf*)'
./obj/local/arm64-v8a/objs/PortaKES/PortaKES.o: In function `Java_com_kurzweil_portakes_POLEFile_destroy':
C:\Users\niels.mylle\Documents\Kurzweil Mobile Android\PortaKES/jni/PortaKES.cpp:48: undefined reference to `CPoleFile::~CPoleFile()'
./obj/local/arm64-v8a/objs/PortaKES/PortaKES.o: In function `Java_com_kurzweil_portakes_POLEFile_exists':
C:\Users\niels.mylle\Documents\Kurzweil Mobile Android\PortaKES/jni/PortaKES.cpp:100: undefined reference to `CPoleFile::exists(char const*)'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/arm64-v8a/libPortaKES.so] Error 1

1 个答案:

答案 0 :(得分:2)

也许这只是问题的一部分,但至少这个参考是错误的:

LOCAL_SRC_FILES := libkes.a

您正在为所有ndk兼容架构构建,但始终为每个架构引用相同的静态预构建,这是无法工作的。

对于您定位的每个架构,您应该使用不同的.a,例如./armeabi/libkes.a./x86/libkes.a./armeabi-v7a/libkes.a等。在这种情况下,您将能够引用您的.a使用TARGET_ARCH_ABI变量,如下所示:

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libkes.a