未定义的引用 SHA_Update。 C 中的 OpenSSL

Undefined reference SHA_Update . OpenSSL in C

我正在学习 OpenSSL 以获取 C 文件的哈希值。当我编译代码时,我在 SHA_Update 和 SHA_Final

中遇到此未定义引用错误

代码如下:

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

#define BUFF_SIZE 256

int main(int argc, char* argv[]) {
   int fd;
   char buff[BUFF_SIZE];
   int i = 0;

   SHA_CTX sha_ctx;
   unsigned char sha_hash[SHA_DIGEST_LENGTH];

   SHA1_Init(&sha_ctx);

   fd = open(argv[1], O_RDONLY, 0);
   do {
      i = read(fd, buff, i);
      SHA_Update(&sha_ctx, buff, i);
   } while(i > 0);
   close(fd);

   SHA_Final(sha_hash, &sha_ctx);

   printf("\n Hash of the file: %s \n\n", argv[1]);
   for(i = 0; i < SHA_DIGEST_LENGTH; ++i) {
      printf("%x", sha_hash[i]);
   }
   printf("\n\n");
   return 0;
}

为了编译我使用了:

gcc -g hash.c -lcrypto

函数名称是:SHA1_UpdateSHA1_Final(您有 SHA_UpdateSHA_Final,看到缺少的 1 了吗?)