编译和交叉编译curl

一、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 <stdio.h>
#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

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值