加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C:动态链接OpenSSL库时出错

发布时间:2020-12-16 06:51:00 所属栏目:百科 来源:网络整理
导读:我有一个C程序,它使用OpenSSL库中的AES例程. 我安装了必要的库(libssl-dev) 我可以静态编译我的程序: gcc -s -o aes aes.c /usr/lib/x86_64-linux-gnu/libcrypto.a 但是当我尝试动态编译它时,我得到以下错误: $gcc -s -o aes aes.c -lcrypto/tmp/ccofFr4N.
我有一个C程序,它使用OpenSSL库中的AES例程.
我安装了必要的库(libssl-dev)

我可以静态编译我的程序:

gcc -s -o aes aes.c /usr/lib/x86_64-linux-gnu/libcrypto.a

但是当我尝试动态编译它时,我得到以下错误:

$gcc -s -o aes aes.c -lcrypto
/tmp/ccofFr4N.o: In function `encrypt':
aes.c:(.text+0x9f): undefined reference to `aesni_set_encrypt_key'
aes.c:(.text+0xd9): undefined reference to `aesni_cbc_encrypt'
aes.c:(.text+0x1a0): undefined reference to `aesni_cbc_encrypt'
/tmp/ccofFr4N.o: In function `decrypt':
aes.c:(.text+0x2d4): undefined reference to `aesni_set_decrypt_key'
aes.c:(.text+0x31e): undefined reference to `aesni_cbc_encrypt'
collect2: error: ld returned 1 exit status

为什么我不能用动态链接的OpenSSL编译我的程序?

UPDATE

那么,这里是来自libssl-dev的库:

$ls /usr/lib/x86_64-linux-gnu/libcrypto.*
/usr/lib/x86_64-linux-gnu/libcrypto.a
/usr/lib/x86_64-linux-gnu/libcrypto.so
/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0

我注意到了以下内容.当我为他们寻找AES函数的名称时,只有libcrypto.a匹配.

$grep aesni_set_encrypt_key /usr/lib/x86_64-linux-gnu/libcrypto.*
Binary file /usr/lib/x86_64-linux-gnu/libcrypto.a matches

/usr/lib/x86_64-linux-gnu/libcrypto.so不应包含这些功能吗?

解决方法

很可能/usr/lib / x86_64-linux-gnu /不是编译器搜索路径的一部分.

建议,在-lcrypto之前插入参数:-L /usr/lib / x86_64-linux-gnu /

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读