简体   繁体   中英

link to a static library using NDK

I have a static library (.a and .h files) from other company. The library is for ios. I am wondering whether I can link this library to my android app using NDK?

I tried it but got some errors here is my android.mk (I put .a and .h files in jni folder)

include $(CLEAR_VARS)
LOCAL_MODULE := staticLib
LOCAL_SRC_FILES := staticLib.a
LOCAL_EXPORT_C_INCLUDES := ./
include $(PREBUILT_STATIC_LIBRARY)

include $(call all-subdir-makefiles)
include $(CLEAR_VARS)

LOCAL_MODULE    := shareLib
LOCAL_SRC_FILES := shareLib.cpp

LOCAL_LDLIBS := -llog -ldl
LOCAL_STATIC_LIBRARIES := staticLib
include $(BUILD_SHARED_LIBRARY)

I got this errors when I build the project

make: * [obj/local/armeabi-v7a/shareLib.so] Error 1

I wonder whether you can link the same. Since the library needs to be cross compiled with Android NDK. Android uses bionic library which has limited functionality. So, mostly it may not work.

A static library built for iOS will certainly not work on Android, you really need to recompile the sources with an Android-compatible toolchain instead (eg like the one provided with the NDK).

The same is tree for static libraries built for Linux/ARM, which provides a completely different runtime / C library.

Apart from that, do not call all-subdir-makefiles before doing other module declarations, because this will mess up your LOCAL_PATH definition (this is unfortunately a GNU Make issue that cannot be work-arounded by ndk-build).

Simply put the call at the end of you Android.mk instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM