【问题标题】:Hash function SHA1 in C++ [duplicate]C ++中的哈希函数SHA1 [重复]
【发布时间】:2013-05-11 00:56:26
【问题描述】:

我想使用 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/sha.h,但是当我想在eclipse中构建项目或从终端构建时,我得到了这个错误:

Hash.cpp:(.text+0x4a): undefined reference to `SHA1'
collect2: error: ld returned 1 exit status

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

【问题讨论】:

  • 所以你需要链接库。您使用什么命令从终端构建?

标签: c++ ubuntu openssl sha1


【解决方案1】:

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

从终端

g++ -o hash hash.cpp -lcrypto

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    • 2011-06-23
    相关资源
    最近更新 更多