2012-02-11 105 views
0

我正在製作一個庫,我的目標是在Android和Windows中使用。 對於使用Visual Studio 2010的Windows,它編譯,鏈接並正常運行。模糊的鏈接錯誤與GCC,但不是VC++

對於Android,我使用的是android-ndk-r7(使用gcc 4.4.3)的ndk-build腳本。 我收到幾個這樣的鏈接錯誤:

./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到一個共享庫,而不是靜態的它編譯。這意味着什麼?

感謝

+0

也許這將幫助:http://stackoverflow.com/questions/7427748/how-do-i-turn-on-rtti-with-cygwin – Asaf 2012-02-11 21:04:35

+0

你使用'-fvisiblity =隱藏「選項? – Troubadour 2012-02-11 21:11:34

+0

@Troubadour:nope – KaiserJohaan 2012-02-11 21:22:41

回答

0

這是一個有點猜測,但該類名字聽起來像它可能是與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 
+0

並沒有幫助,不幸的是 – KaiserJohaan 2012-02-11 20:46:41

+0

@KaiserJohaan啊然後我猜猜猜錯了。我用另一種可能性更新了我的答案。儘管這可能是錯誤的。 – obmarg 2012-02-11 20:53:01

+0

已經在使用它,也沒有工作:p這些錯誤真的很神祕。我想知道爲什麼它鏈接在Windows上,但不是與android/gcc? – KaiserJohaan 2012-02-11 20:59:17