GCC: Simple inheritance test does not work

I am creating an open source 2D engine called YoghurtGum. I am currently working on an Android port using the NDK provided by Google.

I went crazy because of the errors that I received in my application, so I made a simple test program:

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;
}

Seems easy enough, right? This is how I compile it, just like I compile the rest of my code:

/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

(For clarity, line breaks are added). It compiles fine. But then we move on to the linker:

/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

As you probably can say, there are a lot of cool things that really aren't needed. This is because it does not work. It does not work with the following errors:

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

These are the same errors that I get from my actual application.

- , , , , .

.

UPDATE:

, :

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
+3
3

g++ , gcc:

/home/oem/android-ndk-r3/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-g++
-Wl,
--entry=main,
...

. -nostdlib. ( , ). , ?

+9

, . , . , .

, - .

+1

Try adding command line -fno-rtti -fno-exceptionsin g ++

+1
source

Source: https://habr.com/ru/post/1743558/


All Articles