一、环境介绍
宿主机: Redhat 6.3 32位
目标开发板型号: 友善之臂Tiny4412
目标开发板操作系统: 使用busybox制作,内核使用官方3.5内核。
使用的编译器版本: 友善之臂光盘里自带的交叉编译器版本4.5.1
二、编译移植curl
curl命令是利用URL语法在命令行下工作的文件传输工具,1997年首次发行,常用来请求 Web 服务器----可以看做是基于命令行运行的浏览器。它的名字就是客户端(client)的 URL 工具的意思。
它的功能非常强大,命令行参数多达几十种。它支持文件上传和下载,所以是综合传输工具,但按传统,习惯称cURL为下载工具,cURL还包含了用于程序开发的libcurl库,可以直接使用C语言调用。
cURL支持的通信协议有FTP、FTPS、HTTP、HTTPS、TFTP、SFTP、Gopher、SCP、Telnet、DICT、FILE、LDAP、LDAPS、IMAP、POP3、SMTP和RTSP。
curl还支持SSL认证、HTTP POST、HTTP PUT、FTP上传, HTTP form based upload、proxies、HTTP/2、cookies、用户名 密码认证(Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos)、file transfer resume、proxy tunneling。
2.1 下载源代码
源码下载地址: https://curl.haxx.se/download.html
2.2 curl使用介绍
参考文章: https://blog.csdn.net/xiaolong1126626497/article/details/108980098
2.3 交叉编译curl
代码语言:javascript复制[wbyq@wbyq work]$ tar xvf /mnt/hgfs/linux-share-dir/curl-7.73.0.tar.gz
[wbyq@wbyq work]$ cd curl-7.73.0/
[wbyq@wbyq curl-7.73.0]$ ./configure --prefix=$PWD/_install --host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g
[wbyq@wbyq curl-7.73.0]$ make && make install
2.4 部署开发板运行环境
编译成功之后,将install目录下的lib和bin目录下的文件拷贝到开发板的对应目录下即可。
代码语言:javascript复制[wbyq@wbyq curl-7.73.0]$ cd _install/
[wbyq@wbyq _install]$ ls
bin include lib share
[wbyq@wbyq _install]$ cp bin/* /home/wbyq/work/rootfs/bin/
[wbyq@wbyq _install]$ cp lib/*.so* /home/wbyq/work/rootfs/lib/
2.5 测试curl命令
开发板上运行测试:
使用curl命令访问百度首页: (注意: 要访问网页或者下载文件,当前开发板的网卡要先连接网络,比如使用小米随身WIFI先连接手机热点,保证能上网)
代码语言:javascript复制[root@wbyq ]# ls
bin etc linuxrc nfs.sh root sys var
code home lost found opt rootfs tmp work
dev lib mnt proc sbin usr
[root@wbyq ]# curl www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http://www.baidu.com/?bdorz_come=1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=' encodeURIComponent(window.kk (window.location.search === "" ? "?" : "&") "bdorz_come=1") '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
[root@wbyq ]#
获取南昌未来7天的天气预报:
代码语言:javascript复制[root@wbyq ]# ls
bin etc linuxrc nfs.sh root sys var
code home lost found opt rootfs tmp work
dev lib mnt proc sbin usr
[root@wbyq ]# curl "http://api.k780.com:88/?app=weather.future&weaid=??&&appkey=
10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json"
{"success":"1","result":[{"weaid":"237","days":"2020-11-14","week":"星期六","cityno":"nanchang","citynm":"南昌","cityid":"101240101","temperature":"23℃/14℃","humidity":"0%/0%","weather":"晴","weather_icon":"http://api.k780.com/upload/weather/d/0.gif","weather_icon1":"http://api.k780.com/upload/weather/n/0.gif","wind":"东北风转北风","winp":"3-4级","temp_high":"23","temp_low":"14","humi_high":"0","humi_low":"0","weatid":"1","weatid1":"1","windid":"1","winpid":"1","weather_iconid":"0","weather_iconid1":"0"},{"weaid":"237","days":"2020-11-15","week":"星期日","cityno":"nanchang","citynm":"南昌","cityid":"101240101","temperature":"25℃/15℃","humidity":"0%/0%","weather":"晴","weather_icon":"http://api.k780.com/upload/weather/d/0.gif","weather_icon1":"http://api.k780.com/upload/weather/n/0.gif","wind":"东北风转北风","winp":"小于3级","temp_high":"25","temp_low":"15","humi_high":"0","humi_low":"0","weatid":"1","weatid1":"1","windid":"1","winpid":"0","weather_iconid":"0","weather_iconid1":"0"},{"weaid":"237","days":"2020-11-16","week":"星期一","cityno":"nanchang","citynm":"南昌","cityid":"101240101","temperature":"25℃/16℃","humidity":"0%/0%","weather":"晴转多云","weather_icon":"http://api.k780.com/upload/weather/d/0.gif","weather_icon1":"http://api.k780.com/upload/weather/n/1.gif","wind":"东北风转北风","winp":"小于3级","temp_high":"25","temp_low":"16","humi_high":"0","humi_low":"0","weatid":"1","weatid1":"2","windid":"1","winpid":"0","weather_iconid":"0","weather_iconid1":"1"},{"weaid":"237","days":"2020-11-17","week":"星期二","cityno":"nanchang","citynm":"南昌","cityid":"101240101","temperature":"27℃/22℃","humidity":"0%/0%","weather":"多云","weather_icon":"http://api.k780.com/upload/weather/d/1.gif","weather_icon1":"http://api.k780.com/upload/weather/n/1.gif","wind":"南风","winp":"小于3级转小于3级","temp_high":"27","temp_low":"22","humi_high":"0","humi_low":"0","weatid":"2","weatid1":"2","windid":"4","winpid":"0","weather_iconid":"1","weather_iconid1":"1"},{"weaid":"237","days":"2020-11-18","week":"星期三","cityno":"nanchang","citynm":"南昌","cityid":"101240101","temperature":"30℃/21℃","humidity":"0%/0%","weather":"多云转小雨","weather_icon":"http://api.k780.com/upload/weather/d/1.gif","weather_icon1":"http://api.k780.com/upload/weather/n/7.gif","wind":"南风转西南风","winp":"4-5级转4-5级","temp_high":"30","temp_low":"21","humi_high":"0","humi_low":"0","weatid":"2","weatid1":"8","windid":"4","winpid":"2","weather_iconid":"1","weather_iconid1":"7"},{"weaid":"237","days":"2020-11-19","week":"星期四","cityno":"nanchang","citynm":"南昌","cityid":"101240101","temperature":"26℃/16℃","humidity":"0%/0%","weather":"小雨转阴","weather_icon":"http://api.k780.com/upload/weather/d/7.gif","weather_icon1":"http://api.k780.com/upload/weather/n/2.gif","wind":"北风","winp":"3-4级","temp_high":"26","temp_low":"16","humi_high":"0","humi_low":"0","weatid":"8","weatid1":"3","windid":"8","winpid":"1","weather_iconid":"7","weather_iconid1":"2"},{"weaid":"237","days":"2020-11-20","week":"星期五","cityno":"nanchang","citynm":"南昌","cityid":"101240101","temperature":"22℃/21℃","humidity":"0%/0%","weather":"阴","weather_icon":"http://api.k780.com/upload/weather/d/2.gif","weather_icon1":"http://api.k780.com/upload/weather/n/2.gif","wind":"北风","winp":"4-5级","temp_high":"22","temp_low":"21","humi_high":"0","humi_low":"0","weatid":"3","weatid1":"3","windid":"8","winpid":"2","weather_iconid":"2","weather_iconid1":"2"}]}[root@wbyq ]#