Android build fails?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Android build fails?

Post by Ras »

Hi,

I'm trying to make an Android compile of my C engine under Win7. I got the Android NDK and used that included Python script to make a standalone toolchain.

I want to simply use the GCC like I'm also using the MingW GCC, from a build batch file. So I'm calling GCC with a bunch of C files all at once, a lot of compiler options and the -o option to tell what output file I want.

That works also nicely for the bare metal GCC I'm using for the build for my microcontroller target platform. No need to set any special paths or stuff. However, the Android NDK is behaving completely differently.

Things compile nicely, all headers are found. Since I've set -Werror, unknown functions would already cause the compilation to fail.

The issue now is that I'm running into linker problems: undefined references to stuff from the C standard library. I guess that either I have to configure something to the PATH variable, possibly right in the build batch file, or that I have to add some -ldunnowhat to the compiler call to get some libraries added.

Code: Select all

C:\Users\ras\AppData\Local\Temp\ccpdbTSL.o: In function `Play_Xboard':
play.c:(.text+0xc40): undefined reference to `signal'
play.c:(.text+0x1bd4): undefined reference to `stdout'
play.c:(.text+0x1bd8): undefined reference to `stdin'
C:\Users\ras\AppData\Local\Temp\ccpdbTSL.o: In function `main':
play.c:(.text.startup+0x118): undefined reference to `srand'
play.c:(.text.startup+0x1f4): undefined reference to `stdout'
C:\Users\ras\AppData\Local\Temp\cccu1wsd.o: In function `Book_Is_Line':
book.c:(.text+0x624): undefined reference to `rand'
C:\Users\ras\AppData\Local\Temp\cc5GGOKD.o: In function `Search_Get_Best_Mov
e':
search.c:(.text+0x3f04): undefined reference to `stdout'
collect2.exe: error: ld returned 1 exit status

On a second question, my engine is allocating around 230 MB for the hash tables on startup. I want to support also older Android devices, e.g. the Galaxy S4 mini has something like 1.5 GB RAM.

What amount of available RAM can I reasonably expect, assuming that also MP3 playback may be going on, a browser in the background, and of course some xboard-protocol capable chess GUI running?
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Android build fails?

Post by jdart »

clang is the preferred compiler for NDK now. You might try that.

--Jon
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Android build fails?

Post by Ras »

jdart wrote:clang is the preferred compiler for NDK now. You might try that.
Thanks, now I get a linked binary! :-)

In fact, I was already wondering why NDK still has GCC 4.9.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Android build fails?

Post by Ras »

Just wanted to share the results, maybe it's of interest for people thinking about an Android port. It's quite easy for a C engine.

- Get the Android NDK (not the SDK).
- Use the python script android-ndk-r15b/build/tools/make_standalone_toolchain.py with the following options:

Code: Select all

make_standalone_toolchain.py --arch arm --api 16 --unified-headers --install-dir c:\android-standalone-chain
API level 16 is important because that's the minimum where position independent executables (PIE) are supported - and from Android 5.0, that is even mandatory. By default, the script would assume API level 14, so the code would be unlikely to work with Android 5.0.
- I'm using the following build options for Clang:

Code: Select all

-march=armv7-a -m32 -mfloat-abi=softfp -mfpu=vfpv3-d16 -pie -fPIE -Wl,--fix-cortex-a8 -Wall -Wuninitialized -Wstrict-aliasing -Wno-unused-command-line-argument -O2 -std=c99 -fno-strict-aliasing -fno-strict-overflow -ffunction-sections -fdata-sections -Wl,--gc-sections -static
- the binary size can be reduced further using arm-linux-androideabi-strip in the bin/ directory:

Code: Select all

arm-linux-androideabi-strip --strip-unneeded  enginebinary
stdin/stdout work as usual. The only code change I had to make was for the time routine. ftime() from sys/timeb.h isn't available, but that function is obsolete anyway. Instead (works also with MingW), use sys/time.h like so:

Code: Select all

int64_t millisecs;
struct timespec timebuffer;
clock_gettime(CLOCK_MONOTONIC, &timebuffer);
millisecs = ((int64_t) timebuffer.tv_sec)*1000LL + (int64_t) (timebuffer.tv_nsec / 1000000L);
That will leave you with an Android engine. Using the GUI "Chess for Android" which can install an engine from SD card will do the rest.
sasachess
Posts: 24
Joined: Wed Nov 05, 2014 11:28 am
Location: Italy

Re: Android build fails?

Post by sasachess »

I was looking for a way to compile from windows to android and finally I succeeded. It works perfectly. Thank you for sharing!
Gurcan Uckardes
Posts: 196
Joined: Wed Oct 29, 2014 12:42 am

Re: Android build fails?

Post by Gurcan Uckardes »

So, i wanna ask whether we may receive some outcome to test and rate under Android? Thanks.
My blog for Android users: http://chesstroid.blogspot.com
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Android build fails?

Post by Ras »

For the CT800 engine, that will be part of the release V1.12, planned for mid-October.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Android build fails?

Post by Ras »

Update: from NDK r16 on, the "unified headers" are the only option, which is why the python generation script doesn't accept the "--unified-headers" option anymore. The script must be called like that:

Code: Select all

make_standalone_toolchain.py --arch arm --api 16 --install-dir c:\android-standalone-chain
sasachess
Posts: 24
Joined: Wed Nov 05, 2014 11:28 am
Location: Italy

Re: Android build fails?

Post by sasachess »

Gurcan Uckardes wrote:So, i wanna ask whether we may receive some outcome to test and rate under Android? Thanks.
I just released version 1.4, including the executable for Android. Please can you test it and tell me if it works? :)

Thank you!

http://sasachess.altervista.org/gogobello
User avatar
abik
Posts: 819
Joined: Fri Dec 01, 2006 10:46 pm
Location: Mountain View, CA, USA
Full name: Aart Bik

Re: Android build fails?

Post by abik »

sasachess wrote:I just released version 1.4, including the executable for Android. Please can you test it and tell me if it works? :)
Seems to work just fine!

Code: Select all

# ./gogobello-android                                                                                        
-------------------------------------------------------------------------------
gogobello chess engine by Salvatore Giannotti
Version 1.4

-------------------------------------------------------------------------------
enter 'console' for console mode... uci

id name gogobello 1.4
id author Salvatore Giannotti
option name Ponder type check default true
option name Hash type spin default 128 min 1 max 8192
option name Clear Hash type button
option name HashEvalSize type spin default 8 min 1 max 1024
option name HashQSize type spin default 8 min 1 max 1024
option name HashPawnSize type spin default 4 min 1 max 24
option name Thread type spin default 1 min 1 max 24
option name OwnBook type check default true
option name RandBook type check default false
option name BookFile type string default Morphius_12.9c.bin
option name Syzygy type check default true
option name dtzPath type string default <empty>
option name wdlPath type string default <empty>
option name SyzygyMen type spin default 5 min 2 max 6
option name SuddenDeath type spin default 20 min 10 max 50
option name MoreTime type spin default 5 min 5 max 15
option name LessTime type spin default 10 min 5 max 15
option name FastGame type spin default 5 min 5 max 15
option name FastOpening type spin default 10 min 5 max 15
Allocated   128 MB for the Hash Table
Allocated     4 MB for the HashPawn Table for Thread 1
Allocated     8 MB for the HashEval Table for Thread 1
Allocated     8 MB for the HashQ Table for Thread 1
uciok