在 Ubuntu 中编译 so: undefined reference to `XXX’原因及解决方案。

随笔3个月前发布 黄军
80 0 0

在 Ubuntu 中编译 SQLCipher libsqlcipher.so: undefined reference to `OPENSSL_init_crypto’原因及解决方案。

一、在 Ubuntu 中编译 SQLCipher,但是当我运行 make 命令时出现此错误:

./.libs/libsqlcipher.so: undefined reference to `OPENSSL_init_crypto’

./.libs/libsqlcipher.so: undefined reference to `HMAC_CTX_new’

./.libs/libsqlcipher.so: undefined reference to `HMAC_CTX_free’

collect2: error: ld returned 1 exit status

Makefile:611: set di istruzioni per l’obiettivo “sqlcipher” nonriuscito

make: *** [sqlcipher] Errore 1

二、出现该问题的原因:根源在于,SQLite 本身是支持加密功能的 (免费版本不提供加密功能,商业版本是支持加密模块)。SQLCipher 是一个开源的SQLite 加密的扩展,支持对 db 文件进行 256位的 AES 加密。

加密库用的是openssl,自 OpenSSL 3.0起,以下函数已被弃用,并且可以通过使用合适的版本值定义OPENSSL_API_COMPAT来完全隐藏,请参阅openssl_user_macros(7):

const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx);

自 OpenSSL

1.1.0 起,以下函数已被弃用,并且可以通过使用合适的版本值定义OPENSSL_API_COMPAT来完全隐藏,请参阅openssl_user_macros(7):

int EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx);

SQLCipher需要的系统的openssl里没有需要的函数,因为版本的问题。

 三、解决方法思路

该问题起因是openssl版本的问题;

[if !supportLineBreakNewLine]

[endif]

1、下边命令查看libsqlcipher.so调用的openssl路径

Ldd –r /usr/lib/aarch64-linux-gnu/libsqlcipher.so

运行结果

ldd -r/usr/lib/x86_64-linux-gnu/libsqlcipher.so

        linux-vdso.so.1 (0x00007ffe7dac9000)

        libcrypto.so.1.1 =>/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f7e5b9ed000)

        libpthread.so.0 =>/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7e5b9ca000)

        libdl.so.2 =>/lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7e5b9c4000)

        libc.so.6 =>/lib/x86_64-linux-gnu/libc.so.6 (0x00007f7e5b7d2000)

        /lib64/ld-linux-x86-64.so.2(0x00007f7e5bdaa000)

2、运行openssl version,查看版本

$ openssl version

OpenSSL 1.1.1f  31 Mar 2020

3、查看libcrypto.so是否有提示找不到的函数

运行strings /lib/x86_64-linux-gnu/libcrypto.so.1.1

| grep OPENSSL_init_crypto

~$strings /lib/x86_64-linux-gnu/libcrypto.so.1.1 | grep OPENSSL_init_crypto

OPENSSL_init_crypto

OPENSSL_init_crypto

这种运行结果,说明libcrypto.so里有,编译找不的接口;找不的原因是so库连接路径不对;编译参数那加上库的路径/lib/x86_64-linux-gnu/libcrypto.so。

运行如果结果没有OPENSSL_init_crypto显示,说明openssl版本不对;需要下载openssl对应的版本;源码编译安装。

总结:

在linux 中编译遇到 undefined reference to `XXX’原因有两种一种是so库的版本不对;

一种是so库的版本较多,连接的版本没有这个接口;说明openssl版本不对;需要下载openssl对应的版本;源码编译安装。

这样就可以解决问题。

在 Ubuntu 中编译 so: undefined reference to `XXX'原因及解决方案。

在 Ubuntu 中编译 so: undefined reference to `XXX'原因及解决方案。

在 Ubuntu 中编译 so: undefined reference to `XXX'原因及解决方案。

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...