c - C 中对 `SHA1' 的 undefined reference

标签 c sha1 dev-c++

<分区>

我正在尝试编译这段用 C 编写的代码:

#include <stdio.h>
#include <stdlib.h>
#include <C:\OpenSSL-Win32\include\openssl\sha.h>
#include <string.h>

main() {
char data[] = "Hello, world!";
size_t length = strlen(data);

unsigned char hash[SHA_DIGEST_LENGTH];
SHA1(data, length, hash);
}

我正在使用 Dev-C++。它给了我错误:对“SHA1”的 undefined reference 。 我创建了这个帖子: Undefined reference to `SHA1' 但我没有解决问题。 谁能帮帮我?

最佳答案

MrCaptain Alex、Rup 和 Barmar 写下了正确的方法,但就我而言,我有 Ubuntu,当我链接时,有必要添加库 -L/usr/lib -lcrypto:

$ gcc -o executable_file source_file.c -L/usr/lib -lcrypto

就是这样;-)

关于c - C 中对 `SHA1' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53212532/

相关文章:

c - 如何使用 -Werror 忽略 gcc 的 "useless storage class"?

c - 在 OpenGL 中读取鼠标坐标单击

C、数组、​​文件格式无法识别

java - 需要帮助将一些 Java 加密转换为 PHP

c - DEV-C++ 通知 : _CRTIMP int_ccdecl printf(const char*, ...)

c - 这是 Clang 优化器错误还是未定义的行为?

c - 解释C代码指令

c - 访问冲突读取位置 0x73726573

md5 - 什么更好? Password_hash 与 SHA256 与 SHA1 与 md5

java - Java 的 SHA1 散列与 Perl 的不匹配