本文共 2553 字,大约阅读时间需要 8 分钟。
在编译或交叉编译curl之前需要对应编译或交叉编译openssl,详细见:
https://blog.csdn.net/qq_43603677/article/details/105064209 先下载curl安装包curl-7.69.1.tar.gz并解压安装包: tar vxf curl-7.69.1.tar.gz:root@kwt-virtual-machine:/home/kwt# tar vxf curl-7.69.1.tar.gz
进入curl-7.69.1目录:
进入curl-7.69.1目录:
执行./configure命令生成Makefile:
root@kwt-virtual-machine:/home/kwt/curl-7.69.1# ./configure --prefix=/home/kwt/curl
然后执行make和make install:
root@kwt-virtual-machine:/home/kwt/curl-7.69.1# make
root@kwt-virtual-machine:/home/kwt/curl-7.69.1# make install
完成后在/home/kwt/下生成curl文件夹,curl安装成功。
下面写一个简单使用libcurl的例子: curl_test.c:#include#include "/home/kwt/curl/include/curl/curl.h" int main(void){ CURL *curl; CURLcode res; /* http://curl.haxx.se/libcurl/c/curl_easy_init.html */ curl = curl_easy_init(); if(curl) { /* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTURL */ curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1/index.html"); /* http://curl.haxx.se/libcurl/c/curl_easy_perform.html */ res = curl_easy_perform(curl); if(CURLE_OK == res) { char *ct; /* ask for the content-type */ /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */ res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct); if((CURLE_OK == res) && ct) printf("We received Content-Type: %s\n", ct); } /* always cleanup */ /* http://curl.haxx.se/libcurl/c/curl_easy_cleanup.html */ curl_easy_cleanup(curl); } return 0;}
执行gcc curl_test.c -o curl_test -L/home/kwt/curl/lib/ -lcurl得到可执行文件,执行可执行文件如下:
root@kwt-virtual-machine:/home/kwt/Test/3# ./curl_test
同样下载安装curl-7.69.1.tar.gz并解压安装包,进入curl-7.69.1目录之后执行一下命令生成Makefile:
CPPFLAGS="-I/home/kwt/openssl/aarch/openssl/ -I/home/kwt/openssl/aarch/openssl/include" LDFLAGS="-L/home/kwt/openssl/aarch/openssl/lib" LIBS="-ldl" ./configure --host=aarch64-linux-gnu CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ --with-ssl --enable-shared --enable-static --disable-dict --disable-ftp --disable-imap --disable-ldap --disable-ldaps --disable-pop3 --disable-proxy --disable-rtsp --disable-smtp --disable-telnet --disable-tftp --disable-zlib --without-ca-bundle --without-gnutls --without-libidn --without-librtmp --without-libssh2 --without-nss --without-zlib --prefix=/home/kwt/curl/aarch/curl
然后执行make和make install生成/home/kwt/curl/aarch/curl。
修改使用libcurl的例子curl_test.c的如下内容:#include "/home/kwt/curl/aarch/curl/include/curl/curl.h"
交叉编译:
aarch64-linux-gnu-gcc curl_test.c -o curl_test -L/home/kwt/curl/aarch/curl/lib/ -lcurl
生成可执行文件(丢到开发板测试)。