树莓派4B开发笔记(四)c语言https访问百度AI人脸识别接口之安装相关库

一、安装openssl库

1.1、下载openssl源码

//https://www.openssl.org/source/
//https://ftp.openssl.org/source/old/1.1.1
wget https://ftp.openssl.org/source/old/1.1.1/openssl-1.1.1i.tar.gz

1.2、解压、配置、编译并安装

tar -xzf openssl-1.1.1i.tar.gz
cd openssl-1.1.1i/
./config
make -j4
sudo make install

二、安装curl库

2.1下载curl源码

//https://github.com/curl/curl/releases/tag/curl-7_71_1
wget https://curl.se/download/curl-7.71.1.tar.bz2

2.2、解压、配置、编译并安装

tar -xjf curl-7.71.1.tar.bz2
cd curl-7.71.1/
./configure --prefix=$HOME/curl --with-ssl
make -j4
make install

三、安装cjson库

3.1、下载源代码

git clone https://github.com/DaveGamble/cJSON

3.2、解压、配置、编译并安装

//unzip cJSON-master.zip 
cd cJSON/
sudo make
sudo make install

3.3、错误解决

error while loading shared libraries: libcjson.so.1: cannot open shared object file: No such file or directory
sudo ldconfig

四、复制cJSON库(补充用法)

4.1、下载源代码

https://github.com/DaveGamble/cJSON

将里面的cJSON.c、cJOSN.h加入工程文件夹编译时加上cJSON.c

4.2、验证

建工程文件夹

工程文件夹包含以下文件
在这里插入图片描述

写测试代码

#include<stdio.h>
#include<stdlib.h>
#include"cJSON.h"

int main(void)
{
    char *data = "{\"hobby\":[\"LOL\",\"sleeping\",\"eat\"],\"tall\":\"170\",\"age\":\"20\"}";
    //从缓冲区中解析出JSON结构
    cJSON * json= cJSON_Parse(data);

    //将传入的JSON结构转化为字符串 并打印
    
    printf("%s\n",cJSON_Print(json));

    
    //将JSON结构所占用的数据空间释放
    cJSON_Delete(json);
    return 0;
}

编译运行

gcc -o test test.c  cJSON.c
./test.c

结果

在这里插入图片描述

五、配置环境变量

sudo vi /etc/profile

最后一行增加

export C_INCLUDE_PATH=$C_INCLUDE_PATH:$HOME/curl/include
export LIBRARY_PATH=$LIBRARY_PATH:$HOME/curl/lib

执行以下命令生效

source /etc/profile

六、编译调用curl库的程序

#include <curl/curl.h>
gcc xxx.c -lcurl -lssl -lcrypto

七、编译调用cjson库的程序

#include <cjson/cJSON.h>
gcc xxx.c -lcjson
  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值