linux-坑爹的undefined reference to `SHA1'

来源:互联网 发布:mac safari添加收藏 编辑:程序博客网 时间:2024/06/15 04:59

一程序需要使用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/opensslmakemake install

原创粉丝点击