freesl 2021-09-22 12:11
浏览 85
已结题

Arduino开发esp32用到的openssl库编译后不能使用

电脑:win10-64bit,开发环境arduino,模块esp32;
做openssl生成2048位私钥,并做证书签证等内容。arduino开发目录下的libopenssl.a库文件没有封装我要使用的函数。
所以想着自己重新封装openssl的库,下载openssl的源码后在电脑端Ubuntu 20.04.2 LTS x86_64系统 和 树莓派环境的Linux系统下都重新编译后生成'libssl.a' 和 'libcrypto.a'文件(并没有'libopenssl.a'文件,后来自己把前面两个.a文件打包成'libopenssl.a'文件),把这个三个.a文件都放到Arduino的库文件目录下,并把相关的.h头文件也放到对应的目录下,调用了很简单的函数,就编译不了。也放到跟程序同一个目录下也不能编译。
下面是Arduino代码:

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/rsa.h>
#include <openssl/bn.h>

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
  RSA *rsa = RSA_new();
  while(1);
}

出错信息如下:

sketch\openssltest.ino.cpp.o:(.literal._Z4loopv+0x0): undefined reference to `RSA_new'

sketch\openssltest.ino.cpp.o: In function `loop()':

F:\tmp\openssltest/openssltest.ino:18: undefined reference to `RSA_new'

collect2.exe: error: ld returned 1 exit status

exit status 1
为开发板 NodeMCU-32S 编译时出错。

排查过程:
网上找了很多方法,都没解决。
我生成的.a文件用nm *.a的方式查看函数和变量,是有这个 `RSA_new'函数的,而且引用的头文件里也有声明的。

用readelf -h *.a查看的时候,内容里machine这一行有区别:
Arduino自带的库文件是Tensilica Xtensa Processor,而我编译的是ARM,如下:

File: libopenssl.a(ssl_cert.o)
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  **Machine:                           Tensilica Xtensa Processor**
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          7320 (bytes into file)
  Flags:                             0x300
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         39
  Section header string table index: 36

File: libopenssl1.a(a_bitstr.o)
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
 ** Machine:                           ARM**
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          2504 (bytes into file)
  Flags:                             0x5000000, Version5 EABI
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         12
  Section header string table index: 11

所以,现在的问题是:
1、我应该怎么生成openssl的库文件,才可以在Arduino里正常引用编译?
2、xtensa-esp32-elf这个编译器可以编译openssl的源码成库文件吗?
3、或者有没有其它方向?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 9月30日
    • 创建了问题 9月22日

    悬赏问题

    • ¥15 鼠标右键,撤销删除 复制 移动,要怎样删除
    • ¥15 使用MATLAB进行余弦相似度计算加速
    • ¥15 服务器安装php5.6版本
    • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
    • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
    • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数
    • ¥15 arcgis处理土地利用道路 建筑 林地分类
    • ¥20 使用visual studio 工具用C++语音,调用openslsx库读取excel文件的sheet问题
    • ¥100 寻会做云闪付tn转h5支付链接的技术
    • ¥15 DockerSwarm跨节点无法访问问题