在OpenSSL中对RSA_generate_key的未定义引用? [英] Undefined reference to RSA_generate_key in OpenSSL?

查看:768
本文介绍了在OpenSSL中对RSA_generate_key的未定义引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件rsatest.c中具有以下代码.我正在尝试生成一个RSA密钥对.

I have the following code in the file rsatest.c. I'm trying to generate a RSA key pair.

#include <openssl/rsa.h>
#include <openssl/pem.h>

int main(){
    RSA *rsa = RSA_generate_key((const int) 1024,(const int) 3, 0, 0);
    return 0;
}

我正在用

gcc -I../include/ -L . -lcrypto -lssl rsatest.c

然后出现以下错误.

 undefined reference to `RSA_generate_key'

我以错误的顺序链接库文件吗?我使用msys和mingw在Windows(64位)上制作了libcrypto.a和libssl.a,并且在同一系统上运行代码.

Am I linking the library files in the wrong order? I made the libcrypto.a and libssl.a on windows (64 bit), with msys and mingw, and I'm running the code on the same system.

RSA_generate_key已在rsa.h中声明.在libcrypto.a中没有定义吗?

RSA_generate_key has been declared in rsa.h. Is it not defined in libcrypto.a?

我也尝试过

gcc -I../include rsatest.c -L . -lcrypto -lssl

我知道链接器将在库中从左到右查找定义.

and I understand that the linker will look for definitions in the libraries going from left to right.

但是,我在

rand_win.o and c_zlib.o

我在网上查询了一下,发现库gdi32和zlib中缺少符号.所以我加了

I looked up online and found the missing symbols in the libraries gdi32 and zlib. So I added

-lz and -lgdi32

编译器没有抱怨缺少库,因此我认为它们与mingw一起存在.仍然,我得到相同的输出.

The compiler did not complain about a missing library, so I assume they are present with mingw. And still, I get the same output.

我还使用了nm,发现在rand_win.o和c_zlib.o中这些符号的确是未定义的.

I also used nm, and found that the symbols were indeed undefined in rand_win.o and c_zlib.o.

为什么链接器似乎无法在这些库中找到定义?

Why cant the linker seem to find definitions in these libraries?

推荐答案

在gcc命令中更改顺序.

Change the order in your gcc command.

gcc -I../include/ rsatest.c -L . -lcrypto -lssl

据我所知,链接器具有未定义符号的列表.当它处理libcrypto.a和libssl.a时,未定义符号列表中没有任何内容,因此他只删除了库.然后,在处理rsatest之后,它在列表中有一些内容,但不会在已处理的库中查找符号.

As far as I know linker has a list of undefined symbols. When it processes libcrypto.a and libssl.a it does not have anything in the list of undefined symbols so he just drops the libraries. Then after processing rsatest it has something in its list but it does not look for symbols in already processed libraries.

这篇关于在OpenSSL中对RSA_generate_key的未定义引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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