1

I am trying to build a shared library using a prebuilt static library. For some reason, building always fails giving undefined reference errors. If I add LOCAL_ALLOW_UNDEFINED_SYMBOLS := true, building succeeds but the shared library is only a few kilobytes while the static library is about 3 megabytes... So it seems something went wrong in linking the static library. I have no idea what it could be. I am only using C++ code.

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 directory structure:

JNI folder structure

Output:

./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 Answer 1

2

Maybe it's just part of the problem, but at least this reference is wrong:

LOCAL_SRC_FILES := libkes.a 

You're building for all the ndk compatible architectures, but always referencing the same static prebuilt for each of them, which cannot work.

You should have a different .a for each architecture you're targeting, ie ./armeabi/libkes.a, ./x86/libkes.a, ./armeabi-v7a/libkes.a, etc. In that case you'll be able to reference your .a using TARGET_ARCH_ABI variable, like so:

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libkes.a 
Sign up to request clarification or add additional context in comments.

1 Comment

All right, after some work, It turned indeed out to be an architecture compatibility problem. After building the static library for each architecture, the undefined references were gone. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.