@oro-oro
2018-03-28T16:19:00.000000Z
字数 2779
阅读 2728
AndroidARM
$ adb push gdb /data/local/tmp/gdb
$ adb shell
# cd /data/local/tmp
# chmod 755 gdb
具体用法可以用这个命令查看:make-standalone-toolchain.sh --help
android-ndk$ ./build/tools/make-standalone-toolchain.sh --platform=android-L --toolchain=arm-linux-androideabi-4.9
Copying prebuilt binaries...
Copying sysroot headers and libraries...
Copying c++ runtime headers and libraries...
Creating package file: /tmp/ndk-bin/arm-linux-androideabi-4.9.tar.bz2
Cleaning up...
Done.
$
$ mkdir ~/toolchains
$ cd ~/toolchains
$ tar -xvjf /tmp/ndk-bin/arm-linux-androideabi-4.9.tar.bz2
$ export PATH=~/toolchains/arm-linux-androideabi-4.9/bin:$PATH #设置PATH环境
/* hello.c: Hello World program */
#include <stdio.h>
int main(int argc, char* argv[]){
printf("Hello ARM World\n");
return 0;
}
$ arm-linux-androideabi-gcc hello.c -o hello
$ adb push hello /data/local/tmp/
2586 KB/s (1542488 bytes in 0.582s)
$ adb shell /data/local/tmp/hello
Hello ARM World!
$
参考 android-ndk-r10d/docs/Programmers_Guide/html/md_3__key__topics__building__s_t_a_n_d_a_l_o_n_e-_t_o_o_l_c_h_a_i_n.html
/* hello.c: Hello World program */
#include <stdio.h>
int main(int argc, char* argv[]){
printf("Hello ARM World\n");
return 0;
}
makefile
NDK_ROOT=D:\android-ndk-r10d
TOOLCHAINS_ROOT=$(NDK_ROOT)/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64
TOOLCHAINS_PREFIX=$(TOOLCHAINS_ROOT)/bin/arm-linux-androideabi
TOOLCHAINS_INCLUDE=$(TOOLCHAINS_ROOT)/lib/gcc/arm-linux-androideabi/4.9/include-fixed
PLATFORM_ROOT=$(NDK_ROOT)/platforms/android-19/arch-arm
PLATFORM_INCLUDE=$(PLATFORM_ROOT)/usr/include
PLATFORM_LIB=$(PLATFORM_ROOT)/usr/lib
MODULE_NAME=hello
RM=rm
FLAGS=-I$(TOOLCHAINS_INCLUDE) \
-I$(PLATFORM_INCLUDE) \
-L$(PLATFORM_LIB) \
-nostdlib \
-lgcc \
-Bdynamic \
-lc
OBJS=$(MODULE_NAME).o \
$(PLATFORM_LIB)/crtbegin_dynamic.o \
$(PLATFORM_LIB)/crtend_android.o
all:
$(TOOLCHAINS_PREFIX)-gcc $(FLAGS) -E $(MODULE_NAME).c -o $(MODULE_NAME).i
$(TOOLCHAINS_PREFIX)-gcc $(FLAGS) -S $(MODULE_NAME).i -o $(MODULE_NAME).s
$(TOOLCHAINS_PREFIX)-gcc $(FLAGS) -c $(MODULE_NAME).s -o $(MODULE_NAME).o
$(TOOLCHAINS_PREFIX)-gcc $(FLAGS) $(OBJS) -o $(MODULE_NAME)
clean:
$(RM) *.o
install:
adb push $(MODULE_NAME) /data/local/tmp/
adb shell chmod 755 /data/local/tmp/$(MODULE_NAME)
adb shell /data/local/tmp/$(MODULE_NAME)