使用FreeImage时,Android NDK链接器错误“未定义对std :: ios_base的引用”
作者:互联网
我试图静态链接Android NDK的libfreeimage.a的开放框架构建(使用native-activity示例作为模板).
当我编译和链接我的项目时,我得到了很多链接器错误:
../../../lib/ndk/armeabi-v7a/libfreeimage.a(ImfTimeCodeAttribute.o):在函数全局构造函数中,键入ImfTimeCodeAttribute.cpp’:
ImfTimeCodeAttribute.cpp :(.text 0x28):undefined reference tostd :: ios_base :: Init :: Init()’
我相信这是一个范围问题,可以通过在代码中添加命名空间或在gcc上使用g来解决.我认为-lstdc可以解决问题,但事实并非如此.
任何帮助将不胜感激.
Android.mk:
LOCAL_PATH := $(call my-dir)/tmp
include $(CLEAR_VARS)
LOCAL_MODULE := androidapp
LOCAL_CFLAGS := -DFREEIMAGE_LIB\
-DANDROID_NDK \
-DDISABLE_IMPORTGL \
-mfpu=vfp -mfloat-abi=softfp \
-ffast-math -O3 -DFPM_ARM
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM -lstdc++ -ldl
LOCAL_STATIC_LIBRARIES := android_native_app_glue
LOCAL_LDLIBS += ../../../lib/ndk/armeabi-v7a/libfreeimage.a
LOCAL_ARM_MODE := arm
SRC-FILES := $(wildcard tmp/*.c*)
SRC-FILES := $(SRC-FILES:tmp/%=%)
LOCAL_SRC_FILES += $(SRC-FILES)
APP_OPTIM := release
APP_ABI := armeabi-v7a
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
解决方法:
最后想出来了 – 对于其他遇到同样问题的人来说,修复方法是为库添加一个模块然后包含库:
LOCAL_PATH := $(call my-dir)/tmp
include $(CLEAR_VARS)
LOCAL_MODULE := freeimage
LOCAL_SRC_FILES := ../../../../lib/ndk/armeabi-v7a/libfreeimage.a
LOCAL_EXPORT_C_INCLUDES := ../../../../lib/inc
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := androidapp
LOCAL_CFLAGS := -DFREEIMAGE_LIB\
-DANDROID_NDK \
-DDISABLE_IMPORTGL \
-mfpu=vfp -mfloat-abi=softfp \
-ffast-math -O3 -DFPM_ARM
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM -ldl -lstdc++
LOCAL_STATIC_LIBRARIES := android_native_app_glue
LOCAL_STATIC_LIBRARIES += freeimage
LOCAL_ARM_MODE := arm
SRC-FILES := $(wildcard tmp/*.c*)
SRC-FILES := $(SRC-FILES:tmp/%=%)
LOCAL_SRC_FILES += $(SRC-FILES)
APP_OPTIM := release
APP_ABI := armeabi-v7a
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
标签:android,android-ndk,linker-errors,freeimage 来源: https://codeday.me/bug/20190531/1187853.html