我正在构建一个名为 YoghurtGum 的开源 2D 游戏引擎。现在我正在使用 Google 提供的 NDK 开发 Android 端口。
由于我在应用程序中遇到的错误,我快要疯了,所以我做了一个简单的测试程序:
class Base
{
public:
Base() { }
virtual ~Base() { }
}; // class Base
class Vehicle : virtual public Base
{
public:
Vehicle() : Base() { }
~Vehicle() { }
}; // class Vehicle
class Car : public Vehicle
{
public:
Car() : Base(), Vehicle() { }
~Car() { }
}; // class Car
int main(int a_Data, char** argv)
{
Car* stupid = new Car();
return 0;
}
看起来很容易,对吧?这是我编译它的方式,这与我编译其余代码的方式相同:
/home/oem/android-ndk-r3/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-g++
-g
-std=c99
-Wall
-Werror
-O2
-w
-shared
-fshort-enums
-I ../../YoghurtGum/src/GLES
-I ../../YoghurtGum/src
-I /home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/include
-c src/Inheritance.cpp
-o intermediate/Inheritance.o
(为清楚起见,添加了换行符)。这编译得很好。但随后我们进入链接器:
/home/oem/android-ndk-r3/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc
-lstdc++
-Wl,
--entry=main,
-rpath-link=/system/lib,
-rpath-link=/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib,
-dynamic-linker=/system/bin/linker,
-L/home/oem/android-ndk-r3/build/prebuilt/linux-x86/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0,
-L/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib,
-rpath=../../YoghurtGum/lib/GLES
-nostdlib
-lm
-lc
-lGLESv1_CM
-z
/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib/crtbegin_dynamic.o
/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib/crtend_android.o
intermediate/Inheritance.o
../../YoghurtGum/bin/YoghurtGum.a
-o bin/Galaxians.android
正如您可能会说的那样,那里有很多不需要的东西。那是因为它不起作用。它失败并出现以下错误:
intermediate/Inheritance.o:(.rodata._ZTI3Car[typeinfo for Car]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
intermediate/Inheritance.o:(.rodata._ZTI7Vehicle[typeinfo for Vehicle]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
intermediate/Inheritance.o:(.rodata._ZTI4Base[typeinfo for Base]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: ld returned 1 exit status
make: *** [bin/Galaxians.android] Fout 1
这些与我从实际应用程序中得到的错误相同。
如果有人可以向我解释我在测试中出了什么问题,或者我在链接器中忘记了什么选项,我将非常非常感激。
提前致谢。
更新:
当我使我的析构函数非内联时,我得到了新的和更令人兴奋的链接错误:
intermediate/Inheritance.o:(.rodata+0x78): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
intermediate/Inheritance.o:(.rodata+0x90): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
intermediate/Inheritance.o:(.rodata+0xb0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: ld returned 1 exit status
make: *** [bin/Galaxians.android] Fout 1