libcurl是免费的轻量级的客户端网络库,支持DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS,POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet, TFTP.支持SSL, HTTPPOST,HTTPPUT, FTP上传, HTTP form上传,代理,cookies, 用户名与密码认证。
系统环境:Ubuntu 14.04.3 LTS
源码:curl-7.49.0.tar.gz (https://curl.haxx.se/download.html)
源码:curl-7.49.0.tar.gz (https://curl.haxx.se/download.html)
交叉编译环境:arm-none-linux-gnueabi-
[zhaojq@virtual-machine]# tar -zxvf
curl-7.49.0.tar.gz
[zhaojq@virtual-machine]# cd curl-7.49.0/
[zhaojq@virtual-machine]# cd curl-7.49.0/
[zhaojq@virtual-machine]# ./configure --prefix=/home/
zhaojq/libcurl --host=arm-none-linux CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++
[zhaojq@virtual-machine]# make
[zhaojq@virtual-machine]# make install
生成成功
[zhaojq@virtual-machine]# make
[zhaojq@virtual-machine]# make install
生成成功
交叉编译后的文件在/home/zhaojq/
libcurl目录下
[zhaojq@virtual-machine libcurl]# ls
bin include lib share
libcurl头文件在include/curl目录
[zhaojq@virtual-machine libcurl/include/curl]# ls
curlbuild.h curl.h curlrules.h curlver.h easy.h mprintf.h multi.h stdcheaders.h typecheck-gcc.h
交叉编译后的动态库文件在lib目录
[zhaojq@virtual-machine libcurl/lib]# ls
[zhaojq@virtual-machine libcurl]# ls
bin include lib share
libcurl头文件在include/curl目录
[zhaojq@virtual-machine libcurl/include/curl]# ls
curlbuild.h curl.h curlrules.h curlver.h easy.h mprintf.h multi.h stdcheaders.h typecheck-gcc.h
交叉编译后的动态库文件在lib目录
[zhaojq@virtual-machine libcurl/lib]# ls
libcurl.a libcurl.la libcurl.so libcurl.so.4 libcurl.so.4.4.0 pkgconfig
编译test实例
https://curl.haxx.se/libcurl/c/example.html
post-callback | An example source code that issues a HTTP POST and we provide the actual data through a read callback. |
[zhaojq@virtual-machine]# vim
libcurl_test.cpp
编译通过,在当前目录生成libcurl_test可执行文件
将/home/zhaojq/libcurl目录下的所有文件和pkgconfig目录都拷贝到ARM设备上文件系统的/lib目录,
将 libcurl_test 拷贝到ARM设备上
将 libcurl_test 拷贝到ARM设备上
执行./libcurl_test
./libcurl_test: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory
./libcurl_test: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory
libcurl运行需要libssl.so.1.0.0的库,ARM移植openssl-1.0.0s.tar.gz详见另一篇文章
http://blog.csdn.net/miaodichiyou/article/details/50385049
移植成功再次执行
./libcurl_test
[root@ARM /]# ./libcurl_test
* Trying 93.184.216.34...
* Connected to example.com (93.184.216.34) port 80 (#0)
> POST /index.cgi HTTP/1.1
Host: example.com
Accept: */*
Content-Length: 44
Content-Type: application/x-www-form-urlencoded
* We are completely uploaded and fine
< HTTP/1.1 404 Not Found
< Cache-Control: max-age=604800
< Content-Type: text/html
< Date: Thu, 19 May 2016 02:45:50 GMT
< Expires: Thu, 26 May 2016 02:45:50 GMT
< Server: EOS (lax004/2813)
< Content-Length: 460
<
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="http://gp1.wpc.edgecastcdn.net/00222B/jtest/pilot_dns_best_pop.js"></script>
</body>
</html>
* Connection #0 to host example.com left intact
* Trying 93.184.216.34...
* Connected to example.com (93.184.216.34) port 80 (#0)
> POST /index.cgi HTTP/1.1
Host: example.com
Accept: */*
Content-Length: 44
Content-Type: application/x-www-form-urlencoded
* We are completely uploaded and fine
< HTTP/1.1 404 Not Found
< Cache-Control: max-age=604800
< Content-Type: text/html
< Date: Thu, 19 May 2016 02:45:50 GMT
< Expires: Thu, 26 May 2016 02:45:50 GMT
< Server: EOS (lax004/2813)
< Content-Length: 460
<
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="http://gp1.wpc.edgecastcdn.net/00222B/jtest/pilot_dns_best_pop.js"></script>
</body>
</html>
* Connection #0 to host example.com left intact
移植成功。