C++: simple inheritance test fails

127 visningar
Hoppa till det första olästa meddelandet

knight666

oläst,
1 maj 2010 10:58:122010-05-01
till 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

oläst,
1 maj 2010 18:09:012010-05-01
till 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

oläst,
4 maj 2010 14:59:332010-05-04
till 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

oläst,
4 maj 2010 15:31:392010-05-04
till 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

oläst,
4 maj 2010 17:18:112010-05-04
till 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

oläst,
5 maj 2010 04:17:132010-05-05
till 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

oläst,
5 maj 2010 09:20:492010-05-05
till 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

oläst,
5 maj 2010 11:33:042010-05-05
till 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
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden