[gambit-list] compiling for arm android on linux

Sonny To son.c.to at gmail.com
Tue May 11 13:23:11 EDT 2021


Thanks Alexander! that was helpful.

I was missing the gcs -link hello.c step. I was able to compile the C
code like this

% gcc -o hello hello.c hello_.c -I"/usr/local/gambit/include" -lgambit
-L/usr/local/gambit/lib/ -lm -ldl  -lutil

However, when I tried to cross compile to arm

% arm-linux-gnueabi-gcc -static -o hello hello.c hello_.c
-I"/usr/local/gambit/include" -lgambit -L/usr/local/gambit/lib/ -lm
-ldl  -lutil

/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld:
/usr/local/gambit/lib//libgambit.a: error adding symbols: file format
not recognized
collect2: error: ld returned 1 exit status

This error probably means I need  to build libgambit.a for ARM.

On Mon, May 10, 2021 at 4:58 AM Alexander Shendi
<Alexander.Shendi at web.de> wrote:
>
> Hi,
>
> I believe you have to use a different C cross compiler to make the executable. I'm assuming you use Linux on x86-64.
> On Ubuntu or Debian you'd say something like "sudo apt install gcc make gcc-arm-linux-gnueabi binutils-arm-linux-gnueabi" or similar, depending on your distro.
>
> The cross compiler will be named something like "arm-linux-gnueabi-gcc". Be sure to generate a static binary, because Android has a different libc ("Bionic") than regular Linux.
>
> The "proper" way to do this is to use the Android NDK, but that's more complicated IMHO.
>
> You should then proceed as follows:
> $ gsc -c hello.scm
> $ gsc -link hello.c
> $ arm-linux-gnueabi-gcc -static -o hello hello.c hello_.c \
>                                              -lgambit - L/your/gambit/path/lib
>
> Depending on wether your phone is 32 or 64 bits you need to substitute "arm" with "aarch64".
> Please note that you at least need a compiled version of the gambit lib for your target platform.
>
> I hope this wasn't too confusing. It might be actually easier to compile  gambit on the phone itself, using either Termux or a Linux chroot.
>
>
>
>
>
>
>
>
>
> Am 9. Mai 2021 21:57:58 MESZ schrieb Sonny To <son.c.to at gmail.com>:
> >How to compile a simple hello world program on x86 to arm for android?
> >
> >--- hello.scm ---
> >(define wassup (lambda ()
> >   (display "hello from scheme\n")))
> >
> >(wassup)
> >---end hello.scm---
> >
> >
> >% gsc -exe -target arm hello.scm
> >% adb push ./hello /data/local/tmp
> >% adb shell /data/local/tmp/hello
> >
> >/system/bin/sh: /data/local/tmp/hello: not executable: 64-bit ELF file
> >
> >% file hello
> >hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
> >dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
> >BuildID[sha1]=64cb09b1432959e8f4f9734d72e99580f6091497, for GNU/Linux
> >3.2.0, with debug_info, not stripped
> >
> >This doesn't like the -target option is generating an ARM binary.
> >
> >I tried to take a different route by generating C code like this but I
> >can't even compile the generated C code on linux x86:
> >
> >% gsc -c hello.scm
> >% gcc hello.c $GAMBIT_HOME/lib/libgambit.a
> >$GAMBIT_HOME/lib//libgambitgsc.a $GAMBIT_HOME/lib/libgambitgsi.a
> >-I$GAMBIT_HOME/include -lm
> >/usr/bin/ld:
> >/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o:
> >in function `_start':
> >(.text+0x24): undefined reference to `main'
> >/usr/bin/ld: /tmp/ccWylAo9.o: in function `___H_hello_23_':
> >hello.c:(.text+0xb4): undefined reference to `___G_wassup'
> >/usr/bin/ld: hello.c:(.text+0x108): undefined reference to
> >`___G_wassup'
> >/usr/bin/ld: hello.c:(.text+0x186): undefined reference to
> >`___G_wassup'
> >/usr/bin/ld: /tmp/ccWylAo9.o: in function `___setup_mod':
> >hello.c:(.text+0x3d4): undefined reference to `___G_hello_23_'
> >/usr/bin/ld: /tmp/ccWylAo9.o: in function `___init_mod':
> >hello.c:(.text+0x400): undefined reference to `___G_hello_23_'
> >/usr/bin/ld: /tmp/ccWylAo9.o: in function `___LNK_hello':
> >hello.c:(.text+0x41a): undefined reference to `___S_hello'
> >/usr/bin/ld: hello.c:(.text+0x428): undefined reference to
> >`___S_hello_23_'
> >/usr/bin/ld: /usr/local/gambit/lib/libgambit.a(os_dyn.o): in function
> >`___dynamic_load':
> >os_dyn.c:(.text+0x1b0): undefined reference to `dlopen'
> >/usr/bin/ld: os_dyn.c:(.text+0x1c8): undefined reference to `dlsym'
> >/usr/bin/ld: os_dyn.c:(.text+0x2d9): undefined reference to `dlerror'
> >/usr/bin/ld: os_dyn.c:(.text+0x305): undefined reference to `dlclose'
> >/usr/bin/ld: /usr/local/gambit/lib/libgambit.a(os_dyn.o): in function
> >`___cleanup_dyn_module':
> >os_dyn.c:(.text+0x4db): undefined reference to `dlclose'
> >/usr/bin/ld: /usr/local/gambit/lib/libgambit.a(os_io.o): in function
> >`___device_stream_setup_from_process':
> >os_io.c:(.text+0x3592): undefined reference to `openpty'
> >collect2: error: ld returned 1 exit status
> >
> >
> >How do I compile the generated C code?
> >
> >Thanks for any help
> >
> >_______________________________________________
> >Gambit-list mailing list
> >Gambit-list at iro.umontreal.ca
> >https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
>
> --
> Ceci n'est pas un courriel.



More information about the Gambit-list mailing list