Android NDK 链接器错误“未定义对 std::ios_base 的引用”使用 FreeImage 时

发布于 2024-10-31 22:55:49 字数 1181 浏览 3 评论 0原文

我正在尝试静态链接 Android NDK 的 libfreeimage.a 开放框架构建(使用本机活动示例作为模板)。

当我编译和链接我的项目时,我收到很多链接器错误,如下所示:

../../../lib/ndk/armeabi-v7a/libfreeimage.a(ImfTimeCodeAttribute.o):在函数 全局构造函数中键入 ImfTimeCodeAttribute.cpp': ImfTimeCodeAttribute.cpp:(.text+0x28): 对 std::ios_base::Init::Init()' 的未定义引用

我相信这是一个范围问题,可以通过在代码中添加命名空间或使用 g++ 而不是 gcc 来解决。我以为 -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)

I am trying to statically link against the open frameworks build of libfreeimage.a for the Android NDK (using the native-activity sample as a template).

When I compile and link my project I get a lot of linker errors along the lines of:


../../../lib/ndk/armeabi-v7a/libfreeimage.a(ImfTimeCodeAttribute.o): In function global constructors keyed to ImfTimeCodeAttribute.cpp':
ImfTimeCodeAttribute.cpp:(.text+0x28): undefined reference to
std::ios_base::Init::Init()'

I believe this is a scoping problem that can be fixed by either adding a namespace to the code or using g++ over gcc. I thought -lstdc++ would fix the problem but it did not.

Any help would be greatly appreciated.

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生百味 2024-11-07 22:55:49

终于弄清楚了 - 对于有同样问题的其他人,解决方法是为库添加一个模块,然后包含该库:


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)

Finally figured this out - for anyone else with the same problem, the fix is to add a module for the library and then include the library:


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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文