linux-坑爹的undefined reference to `SHA1'

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章