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;
}