【问题标题】:Obscure linking error with GCC, but not VC++与 GCC 的模糊链接错误,但不是 VC++
【发布时间】:2012-02-11 20:30:28
【问题描述】:

我正在制作一个我打算在 android 和 windows 中使用的库。 对于 windows,使用 Visual Studio 2010,它可以编译、链接和运行良好。

对于 Android,我将 ndk-build 脚本与 android-ndk-r7 一起使用(它使用 gcc 4.4.3)。 我收到了以下几个链接器错误:

./obj/local/armeabi-v7a/libjonsengine.a(RenderManagerImpl.o):(.data.rel.ro._ZTI1
4IRenderManager[typeinfo for IRenderManager]+0x0): undefined reference to `vtabl
e for __cxxabiv1::__si_class_type_info'
./obj/local/armeabi-v7a/libjonsengine.a(RenderManagerImpl.o):(.data.rel.ro._ZTI1
2IBaseManager[typeinfo for IBaseManager]+0x0): undefined reference to `vtable fo
r __cxxabiv1::__class_type_info'
./obj/local/armeabi-v7a/libjonsengine.a(RenderManagerImpl.o):(.data.rel.ro+0x34)
: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
./obj/local/armeabi-v7a/libjonsengine.a(LogManagerImpl.o):(.data.rel.ro._ZTI11IL
ogManager[typeinfo for ILogManager]+0x0): undefined reference to `vtable for __c
xxabiv1::__si_class_type_info'
./obj/local/armeabi-v7a/libjonsengine.a(LogManagerImpl.o):(.data.rel.ro+0x38): u
ndefined reference to `vtable for __cxxabiv1::__si_class_type_info'
./obj/local/armeabi-v7a/libjonsengine.a(MemoryManagerImpl.o):(.data.rel.ro._ZTI1
4IMemoryManager[typeinfo for IMemoryManager]+0x0): undefined reference to `vtabl
e for __cxxabiv1::__si_class_type_info'
./obj/local/armeabi-v7a/libjonsengine.a(MemoryManagerImpl.o):(.data.rel.ro+0x40)
: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libandroidgame.so] Error 1

这是我的 Android.mk:

LOCAL_PATH:= $(call my-dir)
TOP_PATH := $(LOCAL_PATH)

include $(CLEAR_VARS)
# Main engine
LOCAL_MODULE    := jonsengine
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include/ \
                    $(LOCAL_PATH)/../include/Core/ \
                    $(LOCAL_PATH)/../interface/ \
                    $(LOCAL_PATH)/../include/Render/ \
                    $(LOCAL_PATH)/../include/Utils/ \
                    $(LOCAL_PATH)/../include/Memory/

# Core
LOCAL_SRC_FILES :=  ../src/Core/Engine.cpp

# Rendering
LOCAL_SRC_FILES +=  ../src/Render/RenderManagerImpl.cpp

# Utils
LOCAL_SRC_FILES +=  ../src/Utils/LogManagerImpl.cpp \
                    ../src/Utils/PortableTime.cpp

# Memory
LOCAL_SRC_FILES +=  ../src/Memory/MemoryManagerImpl.cpp \
                    ../src/Memory/MemoryPool.cpp \
                    ../src/Memory/dlmalloc.c

LOCAL_CFLAGS := -DSTRUCT_MALLINFO_DECLARED
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_EXPORT_CFLAGS := $(LOCAL_CFLAGS)
LOCAL_LDLIBS    := -lGLESv2 -llog

include $(BUILD_STATIC_LIBRARY)



# Testing library
include $(CLEAR_VARS)

LOCAL_MODULE    := jonsenginetests
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../Tests/ \
                    $(LOCAL_PATH)/../Tests/Memory/ \
                    $(LOCAL_PATH)/../Tests/Core/

LOCAL_SRC_FILES :=  ../Tests/TestManager.cpp \
                    ../Tests/Memory/MemoryManagerTest.cpp \
                    ../Tests/TestClass1.cpp

LOCAL_CFLAGS :=
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_EXPORT_CFLAGS := $(LOCAL_CFLAGS)
LOCAL_STATIC_LIBRARIES := jonsengine
LOCAL_LDLIBS    :=-llog

include $(BUILD_STATIC_LIBRARY)

我无法猜测该错误的含义或原因。任何人都可以对此有所了解吗?正如我所提到的,它适用于 VC++。

EDIT2

更新了错误日志。这有什么帮助吗?

例如,当我使用“nm RenderManagerImpl.o”时,我会得到“_ZTI4IRenderManager”的“V”符号和“00000000”地址。

EDIT3: 似乎如果我将 jonsenginetests 放入共享库而不是静态编译它。这意味着什么?

谢谢

【问题讨论】:

标签: android c++ windows gcc linker


【解决方案1】:

这有点猜测,但这个类名听起来可能与 RTTI 有关,它在 android NDK 中默认禁用。

假设我是对的,您可以通过将以下内容添加到您的 Android.mk 文件中来为您的应用程序启用 RTTI:

LOCAL_CPP_FEATURES := rtti

要了解更多信息,我建议在 android NDK 中查看 docs\ANDROID-MK.htmldocs\CPLUSPLUS-SUPPORT.html

也可能是您正在使用 android NDK 不支持的标准库的一部分。它的默认支持相当有限。您可以通过在Application.mk 中提供APP_STL 来更改它使用的内容。例如:

APP_STL := gnustl_static

【讨论】:

  • @KaiserJohaan 嗯,我猜猜错了。我用另一种可能性更新了我的答案。但它可能同样是错误的。
  • 已经在使用它,也没有用:p 这些错误真的很神秘。我想知道为什么它在 windows 上链接而不是在 android/gcc 上?
猜你喜欢
  • 2011-08-23
  • 2015-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-26
  • 1970-01-01
  • 2016-11-16
  • 2012-06-05
相关资源
最近更新 更多