linux-坑爹的undefined reference to `SHA1'

本文介绍了一种解决使用OpenSSL中的SHA1方法时出现的未定义引用错误的方法。通过更换链接选项从-lssl到-lcrypto,成功解决了编译问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一程序需要使用openssl中的SHA1方法.安装openssl后,一直报undefined reference to `SHA1'这个错误.

示例程序源码如下:

#include <iostream>
#include <iomanip>
#include <string>
#include <openssl/sha.h>

using namespace std;

int main(int argc, char* argv[])
{
string input;

unsigned char hash[20];

cout << "enter your string: ";
getline(cin, input);

SHA1((unsigned char*)input.c_str(), input.size(), hash);
cout << "the hash was: ";
for(int i = 0; i < 20; ++i) {
cout << hex << setw(2) << setfill('0') << (int)hash[i];
}
cout << endl;
}
网上一搜,都是安装openssl ,编译时候加上-lssl.问题我是整死弄不过。openssl版本换了多个,问题依旧.ubuntu版本从10.04也换到了11.10,问题依旧.

找同学试,他竟然用-lssl编译成功了.坑爹啊..

继续在网上看啊,终于让我看到了.不用-lssl,而用-lcrypto.最后终于编译成功啦.激动啊..特意记录下来.

总结:

    如果遇到这类问题,先试试-lssl,如果不行,换用-lcrypto.我感觉这个还是与系统有关.

附:

  openssl源码安装方法.

  

 ./config --prefix=/usr/local --openssldir=/usr/local/openssl
make
make install

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值