打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
undefined reference to `SHA1’的处理方法 | 大和尚's blog

在linux编程使用openssl库时, 有时候编译文件会出现

undefined reference to SHA1 等类似错误

而SHA1在openssl/sha.h文件中已经定义,且在自己的c文件中也include了该openssl/sha.h !!

 

这时候,在编译的时候应该加上-lcrypto -lssl 选项,即可消除编译错误.

例子: c文件:

#include<stdio.h>
#include<stdint.h>
#include <openssl/sha.h>

int main(int argc,char **argv)

{
printf(“hello world\n”);

unsigned char hash[SHA_DIGEST_LENGTH];

unsigned char content[4096] = {‘\x41′};

uint32_t len = 4096;

unsigned char * res = SHA1(content,len,hash);

printf(“digest length = %d\n”,SHA_DIGEST_LENGTH);

printf(“digest hash = %s”,hash);

return 0;
}

编译方法:

gcc -o use_sha use_sha.c -lcrypto -lssl

运行:

./use_sha
hello world
digest length = 20
digest hash = ??7_?9J???Hs???Pu

已无错误!! 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Arduino 的MD5库 | www.lab
内存中字节操作--高低位的问题
SHA1和MD5算法详解和源码
OpenSSL: 椭圆曲线签名与校验 (ECDSA)
哈希表的C实现(一)
海量数据处理算法—BloomFilter
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服