简体   繁体   中英

Cross compilation for ARM board?

I was trying to cross compile a simple hello program as stand alone application which will run as binary on arm board, but I am facing problem while running hello binary on arm board.

Below are steps I have followed : -

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- hello

Now hello is successfully build when I check file type of hello using file command : -

$file hello hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.31, BuildID[sha1]=0x68edccf6dba1057774e3d7853914578e53889a75, not stripped

When I push this binary in Android Linux phone under /data folder

1- adb push hello /data

2-chmod 777 /data/hello

3- ./hello (but here hello is not able to run)

Can somebody give me hint what mistakes I am making while compling or running binary on phone.

I am getting strange error messages while running program as shown below : -

root@xxx:/data # ./hello

./hello

Open failed: No such file or directory

1|root@xxx:/data # sh hello

sh hello

hello[1]: syntax error: '☺üê4┤¡♣☻♣4' unexpected

1|root@xxx:/data #

Android requires Position Independent Code for native libraries. Try adding -pie -fpie flags to the compiler. Another issue can be the one described by @Joe. On Android, there is a Bionic standard library. If your "hello" program doesn't use any standard call, you can try compiling without standard library (using the toolchain provided in NDK):

arm-linux-androideabi-g++ -pie -fpie -nostdlib hello.c -o hello

Better option however is to create a simple Android.mk file:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS) 
LOCAL_SRC_FILES:= hello.c
LOCAL_MODULE_TAGS:= test
LOCAL_MODULE:= hello
include $(BUILD_EXECUTABLE)

And use it inside already set up Android SDK by issuing mm command.

If you however want to use standard library and for some reason don't want to use Android.mk, then you can download (and build) all Android sources and pass the includes paths to the gcc (example):

arm-linux-androideabi-g++ -pie -fpie --sysroot=<path_to_android_sources>/out/target/product/<product>/obj/
-I<path_to_android_sources>/bionic/libc/arch-arm/include/ -I<path_to_android_sources>/bionic/libc/include/
-<path_to_android_sources>/bionic/libstdc++/include/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM