Linker errors with external NDK library that needs 'cpufeatures'

纵饮孤独 提交于 2019-12-10 19:57:01

问题


I'm trying to build and link freeimage to an android project. I'm close but I'm tripping up on some linker errors from that library.

I'm using this repo: https://github.com/jamcar23/FreeImage-Android/blob/master/jni/freeimage/Android.mk

Freeimage uses the internal NDK library 'cpufeatures' to use xeon chipset features. In the project's 'android.mk', there's a reference to the cpufeatures library:

LOCAL_STATIC_LIBRARIES := cpufeatures

and my library, which statically links to this one, also includes cpufeatures in its LOCAL_STATIC_LIBRARIES statement in that project's android.mk:

LOCAL_STATIC_LIBRARIES := tinyxml freetype2 bullet freeimage cpufeatures

also in my android.mk, I link freeimage like this:

#####FREEIMAGE_LIBRARY_DECLARATION##########
include $(CLEAR_VARS)
LOCAL_PATH = $(TPLIBROOT)/FreeImage-Android
LOCAL_MODULE := freeimage
LOCAL_EXPORT_C_INCLUDES := include
LOCAL_SRC_FILES := obj/local/$(TARGET_ARCH_ABI)/libFreeImage.a
include $(PREBUILT_STATIC_LIBRARY)
###############################################

which, taking note of a previous question I had about the NDK, should take care of specific architectures (I've build freeimage using all available architectures)

freeimage .a and .so libraries appear to build fine but on linking to my library when building the .so, I get this error:

[armeabi-v7a] SharedLibrary  : libAnthracite.so
jni/freeimage/Source/LibWebP/./src/dsp/dsp.cpu.c:108: error: undefined reference to 'android_getCpuFamily'
jni/freeimage/Source/LibWebP/./src/dsp/dsp.cpu.c:109: error: undefined reference to 'android_getCpuFeatures'
jni/freeimage/Source/LibWebP/./src/dsp/dsp.dec.c:745: error: undefined reference to 'VP8DspInitNEON'

which is odd as both libraries do link cpufeatures, so it really ought to be there.

I'm declaring

APP_PLATFORM := android-14
APP_STL := gnustl_static

in the application.mk files for both projects. Also, I've tried placing 'LOCAL_STATIC_LIBRARIES' in different positions in the files and linking libraries in different orders, although that's just guesswork. Does anybody know what might be causing these linker errors?


回答1:


Please follow the official guide to add cpu-features. TL;NR: add $(call import-module,android/cpufeatures) to your Android.mk.




回答2:


I finally got it to work by ensuring that all of my 'application.mk' files for all four of the third party libraries I was using shared a common base file that looks like this:

APP_PLATFORM := android-15
APP_STL      := c++_static
APP_ABI      := all    
APP_OPTIM    := release
APP_SHORT_COMMANDS := true

Which makes keeping them in line easier, ensuring they're all built against the same libraries. Also, I changed the STL implementation from 'gnustl_static' to 'c++_static'



来源:https://stackoverflow.com/questions/49829995/linker-errors-with-external-ndk-library-that-needs-cpufeatures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!