C++: simple inheritance test fails

127 views
Skip to first unread message

knight666

unread,
May 1, 2010, 10:58:12 AM5/1/10
to android-ndk
Hi all,

I'm building an open source 2D game engine called YoghurtGum (http://
code.google.com/p/yoghurtgum/), and I want to port it to Android.
However, I've run into a bit of a snag.

You see, in my engine, every object in a game is derived from
"Object", while actual scene objects are derived from "Entity" (which
has an x and y position). This is important because it allows to
create an array of Entity pointers that will loop over every in-game
object.

I'm trying to compile a simple test using the Android NDK:

class Base
{

public:

Base() { }
virtual ~Base();


}; // class Base

Base::~Base()
{

}

class Vehicle : public Base
{

public:

Vehicle() : Base() { }
~Vehicle();


}; // class Vehicle

Vehicle::~Vehicle()
{

}

class Car : public Vehicle
{

public:

Car() : Vehicle() { }
~Car();

}; // class Car

Car::~Car()
{

}

int main(int a_Data, char** argv)
{
Car* stupid = new Car();

return 0;
}

Here's the command I'm using to compile it:

/home/oem/android-ndk-r3-crystax/build/prebuilt/linux-x86/arm-
eabi-4.4.0/bin/arm-eabi-g++ -g -nostdlib -std=c++0x -Wall -Werror -O2 -
w -shared -fshort-enums -fno-builtin -I ../../YoghurtGum/src/GLES -
I ../../YoghurtGum/src -I /home/oem/android-ndk-r3-crystax/build/
platforms/android-5/arch-arm/usr/include -c src/Inheritance.cpp -o
intermediate/Inheritance.o

Here's my linker command:

/home/oem/android-ndk-r3-crystax/build/prebuilt/linux-x86/arm-
eabi-4.4.0/bin/arm-eabi-g++ -Wl,--entry=main -Wl,-rpath-link=/home/oem/
android-ndk-r3-crystax/build/platforms/android-5/arch-arm/usr/lib -Wl,-
rpath-link=/home/oem/android-ndk-r3-crystax/build/prebuilt/linux-x86/
arm-eabi-4.4.0/arm-eabi/lib -Wl,-dynamic-linker=/system/bin/linker -
Wl,-L/home/oem/android-ndk-r3-crystax/build/platforms/android-5/arch-
arm/usr/lib -Wl,-rpath=../../YoghurtGum/lib/GLES -nostdlib -lstdc++ -
lm -lc -lGLESv1_CM /home/oem/android-ndk-r3-crystax/build/platforms/
android-5/arch-arm/usr/lib/crtbegin_dynamic.o /home/oem/android-ndk-r3-
crystax/build/platforms/android-5/arch-arm/usr/lib/crtend_android.o
intermediate/Inheritance.o ../../YoghurtGum/bin/YoghurtGum.a -o bin/
Galaxians.android

And, unfortunately, these are my errors:

intermediate/Inheritance.o:(.rodata+0x38): undefined reference to
`vtable for __cxxabiv1::__si_class_type_info'
intermediate/Inheritance.o:(.rodata+0x50): undefined reference to
`vtable for __cxxabiv1::__si_class_type_info'
intermediate/Inheritance.o:(.rodata+0x64): undefined reference to
`vtable for __cxxabiv1::__class_type_info'
collect2: ld returned 1 exit status
make: *** [bin/Galaxians.android] Fout 1

Is this related to RTTI? If so, how can I enable RTTI for Android? I'm
already using the patched NDK which supposedly enables it.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

David Turner

unread,
May 1, 2010, 6:09:01 PM5/1/10
to andro...@googlegroups.com
Yes, it's related to RTTI. You should ask Crystax for more information since you're using his modified NDK.
(RTTI it not currently supported by the Android NDK).

knight666

unread,
May 4, 2010, 2:59:33 PM5/4/10
to android-ndk
Same test:

class Base
{

public:

Base() { }
virtual ~Base();

}; // class Base

Base::~Base()
{

}

class Vehicle : public Base
{

public:

Vehicle() : Base() { }
~Vehicle();

}; // class Vehicle

Vehicle::~Vehicle()
{

}

class Car : public Vehicle
{

public:

Car() : Vehicle() { }
~Car();

}; // class Car

Car::~Car()
{

}

int main(int a_Data, char** argv)
{
Car* stupid = new Car();

return 0;

}

Different error:

adb push ./bin/Galaxians.android /system/sbin/Galaxians.android && \
adb shell chmod 777 /system/sbin/Galaxians.android && \
adb shell /system/sbin/Galaxians.android
### Deploying ###
1025 KB/s (252881 bytes in 0.240s)
[1] Segmentation fault /system/sbin/Gal...

Compiling:

/home/oem/android-ndk-r3-crystax/build/prebuilt/linux-x86/arm-
eabi-4.4.0/bin/arm-eabi-g++ \
-I/home/oem/android-ndk-r3-crystax/build/platforms/android-5/arch-
arm/usr/include \
-I../../YoghurtGum/src \
-fpic \
-mthumb-interwork \
-ffunction-sections \
-funwind-tables \
-fstack-protector \
-fno-short-enums \
-D__ARM_ARCH_5__ \
-D__ARM_ARCH_5T__ \
-D__ARM_ARCH_5E__ \
-D__ARM_ARCH_5TE__ \
-march=armv5te \
-mtune=xscale \
-msoft-float \
-mthumb \
-Os \
-fomit-frame-pointer \
-fno-strict-aliasing \
-finline-limit=64 \
-DANDROID \
-DOS_ANDROID \
-O2 \
-DNDEBUG \
-g \
-Wall \
-Werror \
-w \
-c \
-MMD \
-MP \
-MF intermediate/Inheritance.o.tmp \
src/Inheritance.cc \
-o intermediate/Inheritance.o

Linking:

arm-none-linux-gnueabi-g++ \
-nostdlib \
-Bdynamic \
-Wl,-dynamic-linker,/system/bin/linker \
-Wl,--gc-sections \
-Wl,-z,nocopyreloc /home/oem/android-ndk-r3-crystax/build/platforms/
android-5/arch-arm/usr/lib/crtbegin_dynamic.o \
intermediate/Inheritance.o \
/home/oem/android-ndk-r3-crystax/build/prebuilt/linux-x86/arm-
eabi-4.4.0/arm-eabi/lib/libstdc++.a \
/home/oem/android-ndk-r3-crystax/build/prebuilt/linux-x86/arm-
eabi-4.4.0/arm-eabi/lib/libsupc++.a \
/home/oem/android-ndk-r3-crystax/build/prebuilt/linux-x86/arm-
eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/libgcc.a \
/home/oem/android-ndk-r3-crystax/build/platforms/android-5/arch-arm/
usr/lib/libc.so \
/home/oem/android-ndk-r3-crystax/build/platforms/android-5/arch-arm/
usr/lib/libm.so \
-Wl,--no-undefined \
-Wl,-rpath-link=../../YoghurtGum/lib/Android \
-Wl,-rpath-link=/home/oem/android-ndk-r3-crystax/build/platforms/
android-5/arch-arm/usr/lib \
-L ../../YoghurtGum/lib/Android \
-lui \
-lGLESv1_CM \
/home/oem/android-ndk-r3-crystax/build/platforms/android-5/arch-arm/
usr/lib/crtend_android.o \
../../YoghurtGum/bin/YoghurtGum.a \
-o bin/Galaxians.android

Why does it segfault when I do anything with inheritance?

Dmitry Moskalchuk

unread,
May 4, 2010, 3:31:39 PM5/4/10
to andro...@googlegroups.com
Hi,

I've tried build and this simple program. I've modified hello-exe from
my custom distribution and build using android build system - all works
fine. Probably you got crash due to gcc compilation options mess. Start
from hello-exe and see how android build system do that. Just type
(beeing in root of customized ndk distribution):

make APP=hello-exe V=1 clean all

And see which options actually used.

Dmitry Moskalchuk


04.05.2010 22:59, knight666 пишет:

knight666

unread,
May 4, 2010, 5:18:11 PM5/4/10
to android-ndk
Hello Dmitry,

thank you for your post. I've already copied all the settings from an
example build. It compiles just fine, but it crashes when I run it in
the emulator.

On May 4, 9:31 pm, Dmitry Moskalchuk <crys...@gmail.com> wrote:
> Hi,
>
> I've tried build and this simple program. I've modified hello-exe from
> my custom distribution and build using android build system - all works
> fine. Probably you got crash due to gcc compilation options mess. Start
> from hello-exe and see how android build system do that. Just type
> (beeing in root of customized ndk distribution):
>
> make APP=hello-exe V=1 clean all
>
> And see which options actually used.
>

Dmitry Moskalchuk

unread,
May 5, 2010, 4:17:13 AM5/5/10
to andro...@googlegroups.com
Ok, can you just modify apps/hello-exe/main.cc without touching anything
else and build it using Android build system? I did that and have
succesfully run application on both emulator/device.

Dmitry Moskalchuk

knight666

unread,
May 5, 2010, 9:20:49 AM5/5/10
to android-ndk
You are right, when I do it like that it builds just fine.

I've found out where things went wrong. I'm including several (very
old) libraries that I shouldn't, but are needed for OpenGL ES:

libcorecg.so
libcutils.so
libEGL.so
libGLESv1_CM.so
libGLESv2.so
libhardware.so
libhardware_legacy.so
libnetutils.so
libpixelflinger.so
libui.so (does not exist in the NDK)
libutils.so
libwpa_client.so

These are all required to be able to link against libui.so and
libGLESv1_CM.so. I need these libraries for the following function:

g_Window = android_createDisplaySurface();

this creates a native surface on which OpenGL ES resides.

The puzzling thing is that this libray *does not exist*! The code I'm
basing it on is here: http://bieh.net/2009/02/17/android-copengl/

On May 5, 10:17 am, Dmitry Moskalchuk <crys...@gmail.com> wrote:
> Ok, can you just modify apps/hello-exe/main.cc without touching anything
> else and build it using Android build system? I did that and have
> succesfully run application on both emulator/device.
>
> Dmitry Moskalchuk
>

alan

unread,
May 5, 2010, 11:33:04 AM5/5/10
to android-ndk
opengl es is supported in the ndk, however you should create your open
gl window in java then pass the window into the ndk. see the hello-gl2
sample application in the ndk
Reply all
Reply to author
Forward
0 new messages