Openssl aes.h [链接器错误]未定义引用

时间:2012-05-23 10:48:40

标签: c++ c openssl aes

我尝试使用OpenSSL ibaries进行AES解密的简单测试程序。编译器/链接器向我显示错误。编译器:Dev-Cpp

  [Linker error] undefined reference to `AES_set_decrypt_key'
  [Linker error] undefined reference to `AES_decrypt'  

代码:

#include <stdio.h>
#include <openssl/aes.h>
int main(){
AES_KEY k;
unsigned char key[]="2641cf97291c6ea02b930a4e2a824990";
unsigned char in[]="adc8f4ad114433ffaf4597c9738d257c504db763c29d238aa05bd21e1107809f";
unsigned char out[150];

AES_set_decrypt_key(key, 256, &k);
AES_decrypt(in, out, &k);

printf("%s\n", out);

}

TNX

1 个答案:

答案 0 :(得分:5)

您应该链接到openssl库 - 将其添加到命令行:-lssl -lcrypto

编辑:您可能必须使用-L选项明确指定库的位置 - 同时向命令添加-L<openssl_library_directory>