C++ C+中的散列函数SHA1+;

C++ C+中的散列函数SHA1+;,c++,ubuntu,openssl,sha1,C++,Ubuntu,Openssl,Sha1,我想使用openssl库中的SHA1函数散列字符串,我已经下载了该库并将其安装在/usr/include中,下面是我的代码: #include <openssl/sha.h> #include <string.h> #include <stdio.h> int main() { unsigned char digest[SHA_DIGEST_LENGTH]; char string[] = "hello world"; SHA1(

我想使用openssl库中的
SHA1
函数散列字符串,我已经下载了该库并将其安装在
/usr/include
中,下面是我的代码:

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

int main() {

    unsigned char digest[SHA_DIGEST_LENGTH];
    char string[] = "hello world";

    SHA1((unsigned char*) &string, strlen(string), (unsigned char*) &digest);
}

任何帮助都将不胜感激!:)

您没有正确链接
openssl
,如果您在Linux上,您应该链接
crypto

从终端:


在eclipse中,您应该打开
project->Properties
,转到
C/C++Build->Settings
并在
Linker->Libraries
文件夹中添加
crypto

因此您需要针对库进行链接。您用于从终端生成的命令是什么?
Hash.cpp:(.text+0x4a): undefined reference to `SHA1'
collect2: error: ld returned 1 exit status
g++ -o hash hash.cpp -lcrypto