电脑: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、或者有没有其它方向?