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
Afficher les réponses par date
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@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@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
-- Ceci n'est pas un courriel.
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@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@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@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
-- Ceci n'est pas un courriel.
Am Wed, 12 May 2021 00:23:11 +0700 schrieb Sonny To son.c.to@gmail.com:
Thanks Alexander! that was helpful.
...
This error probably means I need to build libgambit.a for ARM.
probably yes.
Yes and there a script for that in `misc` folder named `build-ambit-android.sh`. Didn't try it yet, Francois
On May 12, 2021, at 3:11 PM, Jörg F. Wittenberger Joerg.Wittenberger@softeyes.net wrote:
Am Wed, 12 May 2021 00:23:11 +0700 schrieb Sonny To son.c.to@gmail.com:
Thanks Alexander! that was helpful.
...
This error probably means I need to build libgambit.a for ARM.
probably yes.
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
I managed to build gambit for arm but now I have a problem with compling C code using the android provided tool-chain
export NDK=$ANDROID_SDK_ROOT/ndk-bundle export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64 export TARGET=aarch64-linux-android export API=30 export AR=$TOOLCHAIN/bin/llvm-ar export CC=$TOOLCHAIN/bin/$TARGET$API-clang export AS=$CC export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++ export LD=$TOOLCHAIN/bin/ld export RANLIB=$TOOLCHAIN/bin/llvm-ranlib export STRIP=$TOOLCHAIN/bin/llvm-strip
./configure --prefix=/home/sto/gambit-arm --build=x86_64 --host=$TARGET
the build-ambit-android.sh as pointed out by Francoi Magan is obsolete https://developer.android.com/ndk/guides/standalone_toolchain
this is how I tried to compile hello.c
sto@gambit:~/workspace/hello$ clang --target=aarch64-linux-android-30 hello.c hello_.c -I$GAMBIT/include $GAMBIT/lib/libgambit.a --sysroot=$TOOLCHAIN/llvm/prebuilt/linux-x86_64/sysroot/ In file included from hello.c:40: /home/sto/gambit/include/gambit.h:866:10: fatal error: 'wchar.h' file not found #include <wchar.h> ^~~~~~~~~ 1 error generated. In file included from hello_.c:9499: /home/sto/gambit/include/gambit.h:866:10: fatal error: 'wchar.h' file not found #include <wchar.h> ^~~~~~~~~ 1 error generated. sto@gambit:~/workspace/hello$
sto@gambit:~/android$ find . -name wchar.h ./ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/wchar.h ./ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/wchar.h ./ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/support/solaris/wchar.h ./ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include/wchar.h ./ndk-bundle/sources/cxx-stl/llvm-libc++/include/wchar.h ./ndk-bundle/sources/cxx-stl/llvm-libc++/include/support/solaris/wchar.h ./ndk-bundle/sources/android/support/include/wchar.h
sto@gambit:~/workspace/hello$ ls $TOOLCHAIN/sysroot/usr/include/wchar.h /home/sto/android/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/wchar.h
clang --target=aarch64-linux-android-30 hello.c hello_.c -I$GAMBIT/include $GAMBIT/lib/libgambit.a --sysroot=$TOOLCHAIN/llvm/prebuilt/linux-x86_64/sysroot/ -I$TOOLCHAIN/sysroot/usr/include In file included from hello.c:40: /home/sto/gambit/include/gambit.h:866:10: fatal error: 'wchar.h' file not found #include <wchar.h> ^~~~~~~~~ 1 error generated. In file included from hello_.c:9499: /home/sto/gambit/include/gambit.h:866:10: fatal error: 'wchar.h' file not found
I am not sure how to fix this. I've explicitly added -I$TOOLCHAIN/sysroot/usr/include which is where wchar.h is located but its still complaining that it cannot find that file
On Thu, May 13, 2021 at 2:15 AM Francois Magnan fmagnan@me.com wrote:
Yes and there a script for that in `misc` folder named `build-ambit-android.sh`. Didn't try it yet, Francois
On May 12, 2021, at 3:11 PM, Jörg F. Wittenberger Joerg.Wittenberger@softeyes.net wrote:
Am Wed, 12 May 2021 00:23:11 +0700 schrieb Sonny To son.c.to@gmail.com:
Thanks Alexander! that was helpful.
...
This error probably means I need to build libgambit.a for ARM.
probably yes.
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list