iperf linux版本移植到android (使用工具链方式不是使用Android.mk)

时间:2023-03-09 06:56:34
iperf linux版本移植到android (使用工具链方式不是使用Android.mk)

由于很多程序是用makefile编译linux应用程序的,如果移植到android就要重新写Android.mk,对于不熟悉这个的人来说,特别麻烦,所以这里介绍只修改makefile就能移植到android板子上面。还有试过这种方式,今天就试试。

首先设置export PATH=~/rowboat-android/wl18xx-snq/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin:$PATH 设置arm-linux-androideabi交叉编译工具链

网络上下载iperf 并解压

./configure   CC=arm-linux-androideabi-gcc  CFLAGS=--sysroot=/home/snq/rowboat-android/wl18xx-snq/android-ndk-r9d/platforms/android-17/arch-arm/

生成config.h 和Makefile脚本

然后make all

出现下面的编译结果

g++ -Wall -O2 -o iperf --sysroot=/home/snq/rowboat-android/wl18xx-snq/android-ndk-r9d/platforms/android-17/arch-arm/ -DHAVE_CONFIG_H Client.o Extractor.o Launch.o List.o Listener.o Locale.o PerfSocket.o ReportCSV.o ReportDefault.o Reporter.o Server.o Settings.o SocketAddr.o gnu_getopt.o gnu_getopt_long.o main.o service.o sockets.o stdio.o tcp_window_size.o ../compat/libcompat.a
/usr/bin/ld: Extractor.o: Relocations in generic ELF (EM: 40)
Extractor.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status

google结果显示

http://*.com/questions/8168950/cross-compiling-c-project-relocations-in-generic-elf-em-3

export CXX=/home/matt/CodeSourcery/bin/arm-none-linux-gnueabi-g++

大多都说是g++问题,修改每个makefile里面g++相关的CXX,不要在设置./configure 的时候修改

出显示不能

checking whether the C++ compiler works... no
configure: error: in `/home/snq/rowboat-android/wl18xx-snq/iperf-2.0.5':
configure: error: C++ compiler cannot create executables
See `config.log' for more details.

所有的地方都修改arm-none-linux-gnueabi-g++ 替换g++ 不然会出现很多错误,基本都是这个引起的

继续编译出现

undefined reference to `__gxx_personality_v0'

error: undefined reference to ‘__cxa_end_cleanup’

两个错误

google之后

http://blog.****.net/ctroll/article/details/8629419

http://*.com/questions/329059/what-is-gxx-personality-v0-for

在CFLAGS后面添加

-fno-exceptions  -lstdc++

还有一个 错误

undefined reference to rpl_malloc

http://blog.****.net/linux_lyb/article/details/3536911

后来发现config.h.in里定义了    
#undef malloc
#undef realloc

把这两个去掉, 编译顺利通过。