Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker errors with external NDK library that needs 'cpufeatures'

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?

like image 696
Luther Avatar asked Nov 28 '25 04:11

Luther


1 Answers

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

like image 136
Alex Cohn Avatar answered Nov 30 '25 20:11

Alex Cohn