use*_*098 2 c++ ubuntu openssl sha1
我想使用SHA1的功能从OpenSSL的库散列字符串,我已经下载了该库并安装它/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);
}
Run Code Online (Sandbox Code Playgroud)
它没有任何语法错误,它识别openssl/sha.h,但是当我想在eclipse中构建项目或从终端构建时,我收到此错误:
Hash.cpp:(.text+0x4a): undefined reference to `SHA1'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!:)
你没有正确链接openssl,如果你在Linux上,你应该链接crypto.
从终端:
g++ -o hash hash.cpp -lcrypto
Run Code Online (Sandbox Code Playgroud)
在Eclipse中,你应该打开project->Properties,去C/C++ Build->Settings添加crypto了在Linker->Libraries文件夹中.
| 归档时间: |
|
| 查看次数: |
2836 次 |
| 最近记录: |