无法链接 OpenSSL 代码 [英] Can't link OpenSSL code

查看:26
本文介绍了无法链接 OpenSSL 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个 openssl 简单程序.完整代码如下:

I am trying to build an openssl simple program. Here is the complete code:

#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;
}

我尝试使用以下命令编译它:

I try to compile it using this command:

gcc -I/home/aleksei/openSSL0.9.8/include -o app -L . -lssl -lcrypto tema1.c

我明白了:

 /tmp/ccT1XMid.o: In function `main':
 tema1.c:(.text+0x8d): undefined reference to `AES_set_encrypt_key'
 tema1.c:(.text+0xa7): undefined reference to `AES_encrypt'
 tema1.c:(.text+0xbf): undefined reference to `AES_set_decrypt_key'
 tema1.c:(.text+0xd9): undefined reference to `AES_decrypt'
 collect2: ld returned 1 exit status

我使用的是 Ubuntu 10.04.我怎样才能让它工作?

I am under Ubuntu 10.04. How can I get this to work ?

推荐答案

您可能正在尝试静态链接,但 -L 选项和 -lcrypto 正在寻找要动态链接的文件.要静态链接到特定库,只需在编译器命令行上指定所有源文件之后的 .a 文件即可.

You may be trying to statically link, but the -L option and -lcrypto are looking for a file to link with dynamically. To statically link to a specific library, just specify your .a file on the compiler command line after all your source files.

例如,

gcc -I/home/aleksei/openSSL0.9.8/include -o app tema1.c ./libcrypto.a

这篇关于无法链接 OpenSSL 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆