博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
编译和交叉编译curl
阅读量:3949 次
发布时间:2019-05-24

本文共 2553 字,大约阅读时间需要 8 分钟。

一、Linux下编译curl:

在编译或交叉编译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:

同样下载安装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

生成可执行文件(丢到开发板测试)。

你可能感兴趣的文章
Creating Multiple APKs with 2+ Dimensions 创建两种以上屏幕尺寸多apk支持
查看>>
Abstracting the New APIs 抽象出新的API
查看>>
Proxying to the New APIs 代理新的API
查看>>
Creating an Implementation with Older APIs 用较早版本的APIs实现抽象类
查看>>
Using the Version-Aware Component 使用版本识别组件
查看>>
Enhancing Security with Device Management Policies 加强安全与设备管理策略 Developing for Enterprise
查看>>
Advertising without Compromising User Experience 不降低用户体验的广告
查看>>
Planning Screens and Their Relationships 规划屏幕和它们的关系
查看>>
Planning for Multiple Touchscreen Sizes 规划多个触摸屏尺寸
查看>>
Providing Descendant and Lateral Navigation 提供下一代和横向导航
查看>>
GPS 0183协议GGA、GLL、GSA、GSV、RMC、VTG解释 + 数据解析
查看>>
android如何使得电阻屏在第一次开机时自动叫起屏幕校准程序
查看>>
android如何实现:当开启图案解锁时,取消滑动解锁
查看>>
Providing Ancestral and Temporal Navigation 设计高效的应用导航
查看>>
Putting it All Together: Wireframing the Example App 把APP例子用线框图圈起来
查看>>
Implementing Lateral Navigation 实现横向导航
查看>>
Implementing Ancestral Navigation 实现原始导航
查看>>
Implementing Temporal Navigation 实现时间导航
查看>>
Responding to Touch Events 响应触摸事件
查看>>
Defining and Launching the Query 定义和启动查询
查看>>