读此篇之前,先读前一篇
1.在源码编译的时候,指定交叉编译工具链
lkmao@ubuntu:~$ arm-linux-gnueabi-gcc --version
arm-linux-gnueabi-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
lkmao@ubuntu:~$
(2)Makefile中指定编译链
root@ubuntu:/big/web/boa/boa-0.94.13/src# vi Makefile
root@ubuntu:/big/web/boa/boa-0.94.13/src# make clean
root@ubuntu:/big/web/boa/boa-0.94.13/src# make
把第一篇文章中创建的/boa目录复制过来
root@ubuntu:/big/web/boa/boa-0.94.13/src# cp /boa/ arm_boa/ -R
root@ubuntu:/big/web/boa/boa-0.94.13/src# cp boa boa_indexer arm_boa
root@ubuntu:/big/web/boa/boa-0.94.13/src# cd arm_boa/
root@ubuntu:/big/web/boa/boa-0.94.13/src/arm_boa# cd cgi-bin/
root@ubuntu:/big/web/boa/boa-0.94.13/src/arm_boa/cgi-bin# arm-linux-gnueabi-gcc -o test.cgi test.c
root@ubuntu:/big/web/boa/boa-0.94.13/src/arm_boa/cgi-bin# ls
test.c test.cgi
root@ubuntu:/big/web/boa/boa-0.94.13/src/arm_boa/cgi-bin#
打包arm_boa目录
root@ubuntu:/big/web/boa/boa-0.94.13/src/arm_boa# cd ..
root@ubuntu:/big/web/boa/boa-0.94.13/src# tar cvf arm_boa.tar arm_boa/
arm_boa/
arm_boa/boa.conf
arm_boa/log/
arm_boa/log/error_log
arm_boa/log/access_log
arm_boa/boa.conf.bak
arm_boa/boa
arm_boa/www/
arm_boa/www/index.html
arm_boa/cgi-bin/
arm_boa/cgi-bin/test.cgi
arm_boa/cgi-bin/test.c
arm_boa/mime.types
arm_boa/boa_indexer
arm_boa/access_log
root@ubuntu:/big/web/boa/boa-0.94.13/src# ls arm_boa.tar
arm_boa.tar
root@ubuntu:/big/web/boa/boa-0.94.13/src#
将arm_boa.tar上传到开发板
root@ubuntu:/big/web/boa/boa-0.94.13/src# scp arm_boa.tar root@192.168.0.3:/
arm_boa.tar 100% 390KB 390.0KB/s 00:00
root@ubuntu:/big/web/boa/boa-0.94.13/src#
解压arm_boa.tar,并重命名为boa,将boa目录放到根目录。
运行:
root@hehe:/boa# ./boa
-sh: ./boa: No such file or directory
root@hehe:/boa#
报错了,解决办法:
查看文件类型:没错是arm的。
root@hehe:/boa# file boa_indexer
boa_indexer: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=4c7674c1b3b88e796d5712f5b02912b29ffbccdd, not stripped
root@hehe:/boa# file boa
boa: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=484dc539aca9196e4f706e12c0c2b33c27164f36, not stripped
root@hehe:/boa#
查看依赖库:
root@hehe:/boa# ldd boa
not a dynamic executable
root@hehe:/boa#
正常情况得到的结果应该是下面这样的:
root@hehe:~/bin# ldd app
linux-vdso.so.1 (0x7ea48000)
...
root@hehe:~/bin#
经过一番查看,发现是编译器配置有误,重新修改Makefile文件。
root@ubuntu:/big/web/boa/boa-0.94.13/src# vi Makefile
将arm-linux-gnueabi-gcc修改为arm-linux-gnueabihf-gcc。
再次运行测试:
root@hehe:/boa# ./boa
gethostbyname:: Resource temporarily unavailable
root@hehe:/boa#
发现出错的代码在config.c文件:
276 he = gethostbyname(temp_name);
277 if (he == NULL) {
278 perror("lkmao2:gethostbyname:");
279 exit(1);
280 }
添加打印信息看看temp_name是什么
276 dprintf(2,"temp_name = %s\n",temp_name);
277 he = gethostbyname(temp_name);
278 if (he == NULL) {
279 perror("lkmao2:gethostbyname:");
280 exit(1);
281 }
重新编译,运行:
root@hehe:/boa# ./boa
temp_name = hehe
lkmao2:gethostbyname:: Resource temporarily unavailable
root@hehe:/boa#
猜测 temp_name应该是localhost才对,重新配/etc/hostname文件。
root@hehe:/etc# echo localhost > hostname
root@hehe:/etc#
重启。
运行boa
root@hehe:/boa# ./boa
在windows登录:
调用cgi
测试成功。