交叉编译树莓派的curl库支持ssl

1.开发环境
(1)装有openssl的ubuntu
(2)交叉编译工具arm-linux-gnueabihf-gcc
(3)openssl和libcurl源码
交叉编译工具的安装 https://blog.csdn.net/qq_46777053/article/details/110221159
libcurl源码的获取 https://github.com/curl/curl/releases/tag/curl-7_71_1
openssl源码的获取 终端输入wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1a.tar.gz

2.安装openssl
如果系统已经有,不需要再次安装 通过whereis openssl 命令查看
解压后进入openssl-1.1.1a文件夹

./config       //默认安装位置在/usr/local,此时需要在安装curl时 在后面添加 --wirh-ssl,具体的内容看 curl-7.71.1/docs/dINSTALL.md
make 
sudo make install

以上步骤得到的openssl 是x86的

curl-7.71.1/docs/dINSTALL.md的部分内容

The configure script always tries to find a working SSL library unless
explicitly told not to. If you have OpenSSL installed in the default search
path for your compiler/linker, you don't need to do anything special. If you
have OpenSSL installed in `/usr/local/ssl`, you can run configure like:

    ./configure --with-ssl

3.交叉编译curl
进入解压后的curl-7.71.1

./configure --prefix=$PWD/_installPi --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc    //此命令 运用在 /usr/local 没有ssl
make 
make install

安装成功后 会在curl-7.71.1下生成_insrallPi
在这里插入图片描述
在这里插入图片描述
将libcurl.so.4.6.0动态库传到树莓派,完成了curl库的移植

有个问题:运用交叉编译工具编译得到的——installPi 没看看到支持ssl
执行第一步命令就没有支持
在这里插入图片描述
执行完成后在bin目录下也没有看到ssl
在这里插入图片描述
但是呢,在交叉编译去链 _installPi下的头文件和库,编译出来的可执行文件,传到树莓派上是可以成功连接到翔云平台的

麻烦各位帮我解答一下,嘻嘻嘻。

编译的文件

#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#define true  1
#define false 2
typedef unsigned int bool;

size_t readData( void *ptr, size_t size, size_t nmemb, void *stream)
{
        char buf[1024] = {'\0'};
        strncpy(buf,ptr,1024);
        printf("============= get Data=========================\n");
        printf("%s\n",buf);

}



bool postUrl()
{
    CURL *curl;
    CURLcode res;
    char *postString;

    char img1[128];
    char img2[128];
    char *key = "翔云平台自己的key";
    char *secret = "翔云平台自己的secret";
    int typeld = 21;
    char *format = "xml";

    postString = (char *)malloc(strlen(key)+strlen(secret)+2048);
    sprintf(postString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s","","",key,secret,21,format);

    curl = curl_easy_init();
    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString);    // 指定post内
        curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/faceliu.do");   // 指定url
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, readData);

        res = curl_easy_perform(curl);
        printf("ok!%d\n",res);

        curl_easy_cleanup(curl);
    }
    return true;
}



int main(void)
{
    postUrl();
    return 0;
}            
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值