环境:
CentOS 5.4
VMware 9.0.1 build-894247
一、前期准备工作:
1、下载ndk
http://dl.google.com/android/ndk/android-ndk-r9c-linux-x86.tar.bz2
2、下载adt
http://dl.google.com/android/adt/adt-bundle-linux-x86-20131030.zip
官网地址 http://developer.android.com/sdk/index.html
不明白什么是adt看这里
http://blog.csdn.net/aizquan/article/details/8974750
完成后,将以上两个东西解压到虚拟机上。
二、设置环境变量,将如下路径加进PATH
android-ndk-r9c
adt-bundle-linux-x86-20131030/sdk/platform-tools
adt-bundle-linux-x86-20131030/sdk/tools
三、手机上运行gdbserver(这一步可能比较费事,待补充)
将gdbserver push到手机上。并用adb启动gdbserver。留意版本号!!
130|shell@android:/ $ gdbserver --version
四、在虚拟机上执行
[root@localhost bin]# cd /home/randy/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin
[root@localhost bin]# ./arm-linux-androideabi-gdb
/mnt/hgfs/CodeBlocks/TTS/arm-linux/test 红色部分是你的可执行文件(交叉编译得到的)
GNU gdb (GDB) 7.3.1-gg2 版本号要与gdbserver一致
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>...
Reading symbols from /mnt/hgfs/CodeBlocks/TTS/arm-linux/test...done.
(gdb) shell adb forward tcp:1234 tcp:1234
(gdb) target remote 127.0.0.1:1234
Remote debugging using 127.0.0.1:1234
0x00008120 in _start ()
(gdb) bt
#0 0x00008120 in _start ()
(gdb) b main.c:42
Breakpoint 1 at 0x8290: file src/main.c, line 42.
(gdb) c
Continuing.
Breakpoint 1, main (argc=1, argv=0xbefc1ad4) at src/main.c:42
42 storePunctuationAndWord(cStringToExamine);
(gdb)
补充说明下交叉编译命令的选项
[root@localhost TTS]# arm-linux-androideabi-gcc -g -o arm-linux/test src/main.c src/Table.c src/WordSegment.c src/TTS.c -L /usr/local/arm-linux/lib -static -l charset -l iconv -I /usr/local/arm-linux/include -I ./include
arm-linux-androideabi-gcc交叉编译器,在android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin下
-g 编译出的可执行文件带调试符号
-o arm-linux/test最终可执行文件叫test
src/main.c src/Table.c src/WordSegment.c src/TTS.c 几个源文件
-L /usr/local/arm-linux/lib -static -l charset -l iconv -I /usr/local/arm-linux/include -I ./include 依赖的动态库和头文件路径
原文:http://blog.csdn.net/randyleonard/article/details/19013221