【发布时间】:2025-12-06 12:00:02
【问题描述】:
我正在尝试构建 freeimage 并将其链接到一个 android 项目。我很接近,但我遇到了该库中的一些链接器错误。
我正在使用这个仓库:https://github.com/jamcar23/FreeImage-Android/blob/master/jni/freeimage/Android.mk
Freeimage 使用内部 NDK 库“cpufeatures”来使用至强芯片组功能。在项目的 'android.mk' 中,有对 cpufeatures 库的引用:
LOCAL_STATIC_LIBRARIES := cpufeatures
我的库(静态链接到这个库)还在该项目的 android.mk 的 LOCAL_STATIC_LIBRARIES 语句中包含 cpufeatures:
LOCAL_STATIC_LIBRARIES := tinyxml freetype2 bullet freeimage cpufeatures
也在我的 android.mk 中,我像这样链接 freeimage:
#####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)
###############################################
注意我之前关于 NDK 的一个问题,应该注意特定的架构(我已经使用所有可用的架构构建了 freeimage)
freeimage .a 和 .so 库似乎构建良好,但在构建 .so 时链接到我的库时,我收到此错误:
[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'
这很奇怪,因为这两个库都链接了 cpu 功能,所以它真的应该在那里。
我要声明
APP_PLATFORM := android-14
APP_STL := gnustl_static
在两个项目的 application.mk 文件中。 另外,我尝试将“LOCAL_STATIC_LIBRARIES”放在文件中的不同位置并以不同的顺序链接库,尽管这只是猜测。 有人知道导致这些链接器错误的原因吗?
【问题讨论】:
标签: android android-ndk linker freeimage