Is it possible to compile angelscript by android toolchain

Started by
22 comments, last by BornToCode 14 years, 7 months ago
Hi, "high hand", "cow man". In Chinese, "high hand" means you are expert in some professional area(imaging some one with his hands very high could achive sth that others can not); "cow man" means you are awsome. Ok, so far for hello, get to job. Android is the OS developed by google for cell phone, and now we'd like to make a game engine on it. And finally a compiling problem came to us. If you are familiar with this OS, please help. first angel script do passed the compile on ubuntu. And android's core is linux. But there is somthing different with their file <new> on android: #ifndef __NEW__ #define __NEW__ #include <stddef.h> //!!!! no extent "c++"{ here !!!!!!!!! namespace std { using ::size_t; struct nothrow_t {}; extern const nothrow_t nothrow; } void* operator new(std::size_t); void* operator new[](std::size_t); void operator delete(void*); void operator delete[](void*); void* operator new(std::size_t, const std::nothrow_t&); void* operator new[](std::size_t, const std::nothrow_t&); void operator delete(void*, const std::nothrow_t&); void operator delete[](void*, const std::nothrow_t&); inline void* operator new(std::size_t, void* p) { return p; } inline void* operator new[](std::size_t, void* p) { return p; } // these next two are not really required, since exceptions are off inline void operator delete(void*, void*) { } inline void operator delete[](void*, void*) { } //!!!! } !!!!!!!!!!!! #endif // __NEW__ and linux does. with makefile modified: CXX = arm-eabi-g++ Without "extent c++" we canot pass the compile. arm-eabi-g++ -g -Wall -fPIC -o obj/as_callfunc_x64_gcc.o -c ../../source/as_callfunc_x64_gcc.cpp In file included from ../../source/as_memory.h:75, from ../../source/as_config.h:666, from ../../source/as_callfunc_x64_gcc.cpp:39: /home/Administrator/open_src/android/android-ndk-1.5_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/include/new:18: error: declaration of C function 'void* operator new(size_t, const std::nothrow_t&)' conflicts with /home/Administrator/open_src/android/android-ndk-1.5_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/include/new:14: error: previous declaration 'void* operator new(size_t)' here /home/Administrator/open_src/android/androi d-ndk-1.5_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/include/new:19: error: declaration of C function 'void* operator new [](size_t, const std::nothrow_t&)' conflicts with /home/Administrator/open_src/android/android-ndk-1.5_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/include/new:15: error: previous declaration 'void* operator new [](size_t)' here /home/Administrator/open_src/android/android-ndk-1.5_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/include/new:20: error: declaration of C function 'void operator delete(void*, const std::nothrow_t&)' conflicts with /home/Administrator/open_src/android/android-ndk-1.5_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../ lib/gcc/arm-eabi/4.2.1/include/new:16: error: previous declaration 'void operator delete(void*)' here When we manually added this line to <new> on android, compile passed. But somthing goes wrong with linking arm-eabi-gcc -nostdlib -Bdynamic -Wl,-T,armelf.x -include AndroidConfig.h -lc -o test_main test_main.cpp crtbegin_dynamic.o crtend.o -L./libangelscript.a /cygdrive/c/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ccksYjAl.o: In function `main': test_main.cpp:(.text+0x38): undefined reference to `asCreateScriptEngine' collect2: ld returned 1 exit status so I'd like to ask again : Is it possible to compile angelscript by android toolchain ? or any suggestions? thanks again.
Advertisement
Hi darktemplar,

I believe you only made a little mistake with the commandline. You didn't actually link with the angelscript library. Change it to this:

arm-eabi-gcc -nostdlib -Bdynamic -Wl,-T,armelf.x -include AndroidConfig.h -lc -o test_main test_main.cpp crtbegin_dynamic.o crtend.o -L. -langelscript


You used -L instead of -l to link with the library, however -L only tells the linker the path where it is supposed to look for libraries. -l is for actually linking.

Thanks for the tip on how to fix <new> on android. I'll have to remember that if someone else asks about it.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I modified the commandline as you say then here comes the problem again. But do thanks for your last reply.

commandline:

arm-eabi-gcc -nostdlib -Bdynamic -Wl,-T armelf.x -include AndroidConfig.h -lc -o test_main test_main.cpp crtbegin_dynamic.o crtend.o -L. -langelscript

problem:

./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `asCScriptEngine::RegisterEnumValue(char const*, char const*, int)':
../../source/as_scriptengine.cpp:4123: undefined reference to `__cxa_end_cleanup'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `asCScriptEngine::RegisterEnum(char const*)':
../../source/as_scriptengine.cpp:4086: undefined reference to `__cxa_end_cleanup'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `asCScriptEngine::RegisterInterface(char const*)':
../../source/as_scriptengine.cpp:1023: undefined reference to `__cxa_end_cleanup'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `asCScriptEngine::ParseToken(char const*, unsigned int, int*)':
../../source/as_scriptengine.cpp:636: undefined reference to `__cxa_end_cleanup'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `asCScriptEngine::RegisterTypedef(char const*, char const*)':
../../source/as_scriptengine.cpp:4009: undefined reference to `__cxa_end_cleanup'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o):../../source/as_scriptengine.cpp:3725: more undefined references to `__cxa_end_cleanup' follow
./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `~asCScriptEngine':
../../source/as_scriptengine.cpp:504: undefined reference to `operator delete(void*)'
../../source/as_scriptengine.cpp:504: undefined reference to `__cxa_end_cleanup'
../../source/as_scriptengine.cpp:504: undefined reference to `operator delete(void*)'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `asCScriptEngine':
../../source/as_scriptengine.cpp:377: undefined reference to `__cxa_end_cleanup'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `asCreateScriptEngine':
../../source/as_scriptengine.cpp:193: undefined reference to `__cxa_end_cleanup'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o):(.ARM.extab+0x228): undefined reference to `__gxx_personality_v0'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o):(.ARM.extab+0x268): undefined reference to `__gxx_personality_v0'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o):(.ARM.extab+0x2c0): undefined reference to `__gxx_personality_v0'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o):(.ARM.extab+0x30c): undefined reference to `__gxx_personality_v0'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o):(.ARM.extab+0x330): undefined reference to `__gxx_personality_v0'
./libangelscript_arm-eabi-ld.a(as_scriptengine.o):(.ARM.extab+0x3a8): more undefined references to `__gxx_personality_v0' follow
./libangelscript_arm-eabi-ld.a(as_scriptengine.o): In function `asSSystemFunctionInterface':
../../source/as_callfunc.h:99: undefined reference to `__cxa_end_cleanup'
GCC C++ programs usually need to link with -lstdc++, so try adding that to your commandline.
Huh, u can compile w\ GCC (targeting ARM i assume) and it will run just fine on Android?
==============================
A Developers Blog | Dark Rock Studios - My Site
holly xx..

Now we tried to compile it by using android.mk rather then makefile in angelscript. android.mk is the special makefile for android os. now sth new came out..

target thumb C++: angelscript <= external/angelscript/source/as_arrayobject.cpp
target thumb C++: angelscript <= external/angelscript/source/as_atomic.cpp
target thumb C++: angelscript <= external/angelscript/source/as_builder.cpp
target thumb C++: angelscript <= external/angelscript/source/as_bytecode.cpp
target thumb C++: angelscript <= external/angelscript/source/as_callfunc.cpp
target thumb C++: angelscript <= external/angelscript/source/as_callfunc_mips.cpp
target thumb C++: angelscript <= external/angelscript/source/as_callfunc_ppc.cpp
target thumb C++: angelscript <= external/angelscript/source/as_callfunc_ppc_64.cpp
target thumb C++: angelscript <= external/angelscript/source/as_callfunc_sh4.cpp
target thumb C++: angelscript <= external/angelscript/source/as_callfunc_x86.cpp
target thumb C++: angelscript <= external/angelscript/source/as_callfunc_x64_gcc.cpp
external/angelscript/source/as_callfunc_x64_gcc.cpp: In function 'int CallSystemFunction(int, asCContext*, void*)':
external/angelscript/source/as_callfunc_x64_gcc.cpp:91: error: unknown register name '%rax' in 'asm'
external/angelscript/source/as_callfunc_x64_gcc.cpp:111: error: unknown register name '%rax' in 'asm'
make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/angelscript_intermediates/as_callfunc_x64_gcc.o] Error 1

I think may be you know what happened.
o mips x86, gonna do a little modification
Looks like as_config.h file needs to be modified to correctly identify Android as the target.

You may want to try adding -DAS_MAX_PORTABILITY to the command line to turn off support for native calling conventions to see if that works. Once you get that to work you can look into what needs to be done to add support for native calling conventions on Android.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Oh, good. Done. With a little modification , mission complete! compile ok, link ok!
1.There is no need to modify <new> on android

2.add two lines into as_config.h
#define AS_ARM
#define AS_NO_ATOMIC

3.change the name of as_callfunc_armasm.asm to as_callfunc_armasm.S

4.mofify it as below

//AREA .rdata, DATA, READONLY
//EXPORT armFunc
//EXPORT armFuncR0
//EXPORT armFuncR0R1
//EXPORT armFuncObjLast
//EXPORT armFuncR0ObjLast

.global armFunc
.global armFuncR0
.global armFuncR0R1
.global armFuncObjLast
.global armFuncR0ObjLast


//AREA .text, CODE, ARM

armFunc:
stmdb sp!, {r4-r8, lr}
mov r6, r0 ////; arg table
movs r7, r1 ////; arg size (also set the condition code flags so that we detect if there are no arguments)
mov r4, r2 ////; function address
mov r8, #0

beq nomoreargs

////; Load the first 4 arguments into r0-r3
cmp r7, #4
ldrge r0, [r6],#4
cmp r7, #2*4
ldrge r1, [r6],#4
cmp r7, #3*4
ldrge r2, [r6],#4
cmp r7, #4*4
ldrge r3, [r6],#4
ble nomoreargs

////; Load the rest of the arguments onto the stack
sub r7, r7, #4*4 ////; skip the 4 registers already loaded into r0-r3
sub sp, sp, r7
mov r8, r7
stackargsloop:
ldr r5, [r6], #4
str r5, [sp], #4
subs r7, r7, #4
bne stackargsloop
nomoreargs:
sub sp, sp, r8
blx r4
add sp, sp, r8
ldmia sp!, {r4-r8, pc}


armFuncObjLast:
stmdb sp!, {r4-r8, lr}
mov r6, r0 ////; arg table
movs r7, r1 ////; arg size (also set the condition code flags so that we detect if there are no arguments)
mov r4, r2 ////; function address
mov r8, #0

mov r0, r3 ////; objlast. might get overwritten
str r3, [sp, #-4]! ////; objlast again.

beq nomoreargsarmFuncObjLast

////; Load the first 4 arguments into r0-r3
cmp r7, #4
ldrge r0, [r6],#4
cmp r7, #2*4
ldrge r1, [r6],#4
ldrlt r1, [sp]
cmp r7, #3*4
ldrge r2, [r6],#4
ldrlt r2, [sp]
cmp r7, #4*4
ldrge r3, [r6],#4
ldrlt r3, [sp]
ble nomoreargsarmFuncObjLast

//; Load the rest of the arguments onto the stack
sub r7, r7, #4*4 //; skip the 4 registers already loaded into r0-r3
sub sp, sp, r7
mov r8, r7
stackargslooparmFuncObjLast:
ldr r5, [r6], #4
str r5, [sp], #4
subs r7, r7, #4
bne stackargslooparmFuncObjLast
nomoreargsarmFuncObjLast:
sub sp, sp, r8
blx r4
add sp, sp, r8
add sp, sp, #4
ldmia sp!, {r4-r8, pc}


armFuncR0ObjLast:
stmdb sp!, {r4-r8, lr}
ldr r7, [sp,#6*4]
str r7, [sp], #-4

mov r6, r0 //; arg table
movs r7, r1 //; arg size (also set the condition code flags so that we detect if there are no arguments)
mov r4, r2 //; function address
mov r8, #0

mov r0, r3 //; r0 explicitly set
ldr r1, [sp] //; objlast. might get overwritten

beq nomoreargsarmFuncR0ObjLast

//; Load the first 3 arguments into r1-r3
cmp r7, #1*4
ldrge r1, [r6],#4
cmp r7, #2*4
ldrge r2, [r6],#4
ldrlt r2, [sp]
cmp r7, #3*4
ldrge r3, [r6],#4
ldrlt r3, [sp]
ble nomoreargsarmFuncR0ObjLast

//; Load the rest of the arguments onto the stack
sub r7, r7, #3*4 //; skip the 3 registers already loaded into r1-r3
sub sp, sp, r7
mov r8, r7
stackargslooparmFuncR0ObjLast:
ldr r5, [r6], #4
str r5, [sp], #4
subs r7, r7, #4
bne stackargslooparmFuncR0ObjLast
nomoreargsarmFuncR0ObjLast:
sub sp, sp, r8
blx r4
add sp, sp, r8
add sp, sp, #4
ldmia sp!, {r4-r8, pc}


armFuncR0:
stmdb sp!, {r4-r8, lr}
mov r6, r0 //; arg table
movs r7, r1 //; arg size (also set the condition code flags so that we detect if there are no arguments)
mov r4, r2 //; function address
mov r8, #0

mov r0, r3 //; r0 explicitly set

beq nomoreargsarmFuncR0

//; Load the first 3 arguments into r1-r3
cmp r7, #1*4
ldrge r1, [r6],#4
cmp r7, #2*4
ldrge r2, [r6],#4
cmp r7, #3*4
ldrge r3, [r6],#4
ble nomoreargsarmFuncR0

//; Load the rest of the arguments onto the stack
sub r7, r7, #3*4 //; skip the 3 registers already loaded into r1-r3
sub sp, sp, r7
mov r8, r7
stackargslooparmFuncR0:
ldr r5, [r6], #4
str r5, [sp], #4
subs r7, r7, #4
bne stackargslooparmFuncR0
nomoreargsarmFuncR0:
sub sp, sp, r8
blx r4
add sp, sp, r8
ldmia sp!, {r4-r8, pc}


armFuncR0R1:
stmdb sp!, {r4-r8, lr}
mov r6, r0 //; arg table
movs r7, r1 //; arg size (also set the condition code flags so that we detect if there are no arguments)
mov r4, r2 //; function address
mov r8, #0

mov r0, r3 //; r0 explicitly set
ldr r1, [sp, #6*4] //; r1 explicitly set too

beq nomoreargsarmFuncR0R1

//; Load the first 2 arguments into r2-r3
cmp r7, #1*4
ldrge r2, [r6],#4
cmp r7, #2*4
ldrge r3, [r6],#4
ble nomoreargsarmFuncR0R1

//; Load the rest of the arguments onto the stack
sub r7, r7, #2*4 //; skip the 2 registers already loaded into r2-r3
sub sp, sp, r7
mov r8, r7
stackargslooparmFuncR0R1:
ldr r5, [r6], #4
str r5, [sp], #4
subs r7, r7, #4
bne stackargslooparmFuncR0R1
nomoreargsarmFuncR0R1:
sub sp, sp, r8
blx r4
add sp, sp, r8
ldmia sp!, {r4-r8, pc}


5.final compile it with android way(android.mk).

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= as_callfunc_armasm.S as_arrayobject.cpp as_atomic.cpp as_builder.cpp as_bytecode.cpp as_callfunc.cpp as_callfunc_arm.cpp as_callfunc_mips.cpp as_callfunc_ppc.cpp as_callfunc_ppc_64.cpp as_callfunc_sh4.cpp as_callfunc_x86.cpp as_compiler.cpp as_context.cpp as_configgroup.cpp as_datatype.cpp as_generic.cpp as_gc.cpp as_memory.cpp as_module.cpp as_objecttype.cpp as_outputbuffer.cpp as_parser.cpp as_restore.cpp as_scriptcode.cpp as_scriptengine.cpp as_scriptfunction.cpp as_scriptnode.cpp as_scriptobject.cpp as_string.cpp as_string_util.cpp as_thread.cpp as_tokenizer.cpp as_typeinfo.cpp as_variablescope.cpp
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE := angelscript
include $(BUILD_STATIC_LIBRARY)

Then everything's fine.
a simple test had been passed.
A few more needed.
Let's hope it shall go on well.

Thanks again litchlord.
In Chinese :"xie, xie"
Great work. I'll add these changes to the library. Thanks a lot.

However, to make the changes in as_config.h I need to know what precompiler flags that I can use to detect the Android platform. Can you determine that for me? Usually this is done something like this:

cpp -dD foo.h

Though you need to make sure you use the Android version of the C preprocessor, otherwise the predefines will not be the correct ones.



Maybe with these changes the native calling conventions can be supported on the iPhone as well. Hopefully someone can test that as well.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement