OpenSSL 的链接错误[重复]

2023-12-14

我已经安装了 OpenSSL 。我只想使用 OpenSSL 运行一个程序。

这是我的程序,摘自here .

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "openssl/aes.h"

int main(int argc, char* argv[])
{
  AES_KEY aesKey_;
  unsigned char userKey_[16];
  unsigned char in_[16];
  unsigned char out_[16];
  strcpy(userKey_,"0123456789123456");
  strcpy(in_,"0123456789123456");

  fprintf(stdout,"Original message: %s", in_);
  AES_set_encrypt_key(userKey_, 128, &aesKey_);
  AES_encrypt(in_, out_, &aesKey_);

  AES_set_decrypt_key(userKey_, 128, &aesKey_);
  AES_decrypt(out_, in_,&aesKey_);
  fprintf(stdout,"Recovered Original message: %s", in_);      
  return 0;
}

在编译程序时,我得到了与那里相同的错误消息,但是那里提供的解决方案对我不起作用。

我仍然收到编译错误。

$ gcc -I/home/bholanath/Sources/openssl-1.0.1e/include/ op.c -lcrypt 

/tmp/ccvHr9Jr.o: In function `main':
op.c:(.text+0x9c): undefined reference to `AES_set_encrypt_key'
op.c:(.text+0xbc): undefined reference to `AES_encrypt'
op.c:(.text+0xd7): undefined reference to `AES_set_decrypt_key'
op.c:(.text+0xf7): undefined reference to `AES_decrypt'
collect2: error: ld returned 1 exit status

$ gcc op.c -lcrypt 

/tmp/ccDEZMog.o: In function `main':
op.c:(.text+0x9c): undefined reference to `AES_set_encrypt_key'
op.c:(.text+0xbc): undefined reference to `AES_encrypt'
op.c:(.text+0xd7): undefined reference to `AES_set_decrypt_key'
op.c:(.text+0xf7): undefined reference to `AES_decrypt'
collect2: error: ld returned 1 exit status

任何消除编译错误并运行我的程序的帮助都会很棒。 我在 Fedora linux 下使用 GCC。


OpenSSL 库名称是libcrypto and libssl。尝试将它们链接起来。libcrypt是 glibc 的一部分。

Also, 您的代码无效.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OpenSSL 的链接错误[重复] 的相关文章

随机推荐