在GCC中链接libssl和libcrypto [英] Linking libssl and libcrypto in GCC
问题描述
我试图使用OpenSSL的EVP界面来进行一些加密。我很确定我的代码是正确的,但我似乎无法得到它编译。我使用的是GCC,Ubuntu 32位精确安装了libssl-dev和最新版本。
该项目目前由一个文件 program.c
。
#include< openssl / evp.h>
...
i = EVP_BytesToKey(EVP_aes_256_cbc(),EVP_sha1()...);
...
EVP_CIPHER_CTX_init(e_ctx);
以及其他各种通话。
是我如何调用gcc:
gcc -Wall -g -lssl -lcrypto -o program program.c
然后我得到这样的输出
/home/andy/program/program.c:31:对`EVP_sha1'的未定义引用
也没有运气。
/home/andy/program/program.c:31:对`EVP_aes_256_cbc'的未定义引用
/home/andy/program/program.c:31:对'EVP_BytesToKey'的未定义引用
/home/andy/program/program.c:44:对'EVP_CIPHER_CTX_init'的未定义引用
$ c
$ b因此,包括显然工作:
andy @ ProgStation2:/ usr / include $ find。 | grep evp.h
./openssl/evp.h
以下是
找到libcrypto
。我最好的猜测是,这是一个愚蠢的位置,因此我的链接失败,所以我在之前尝试-L / usr / lib / i386-linux-gnu
code> -lcrypto/ lib / i386-linux -gnu / libcrypto.so.1.0.0
我很难过。如果有人想让我觉得自己是个傻瓜,我会很高兴能够弄清楚我做错了什么! 解决方案
事实证明,这是愚蠢的。在连接器步骤中,我使用 gcc -Wall -g -lssl -lcrypto -o program program.o
。我需要将库链接移动到链接的目标文件后面,并在 libcrypto
之前放置 libssl
:
gcc -Wall -g -o program program.o -lssl -lcrypto
I'm attempting to use OpenSSL's EVP interface to do some encryption. I'm pretty sure my code is right, but I can't seem to get it to compile. I'm using GCC, and Ubuntu 32-bit precise with libssl-dev installed and at the latest version.
The project currently consists of one file, program.c
.
#include <openssl/evp.h>
...
i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1() ... );
...
EVP_CIPHER_CTX_init(e_ctx);
among other various calls.
Here is how I invoke gcc:
gcc -Wall -g -lssl -lcrypto -o program program.c
Then I get output like this
/home/andy/program/program.c:31: undefined reference to `EVP_sha1'
/home/andy/program/program.c:31: undefined reference to `EVP_aes_256_cbc'
/home/andy/program/program.c:31: undefined reference to `EVP_BytesToKey'
/home/andy/program/program.c:44: undefined reference to `EVP_CIPHER_CTX_init'
So the include is clearly working:
andy@ProgStation2:/usr/include$ find . | grep evp.h
./openssl/evp.h
Here is the output of locate libcrypto
. My best guess is that this is a stupid location for it and is why my link is failing, so I tried -L/usr/lib/i386-linux-gnu
before -lcrypto
with no luck as well.
/lib/i386-linux-gnu/libcrypto.so.1.0.0
I'm kind of stumped. If anyone wants to make me feel like a fool, I'd be very excited to figure out what i'm doing wrong!
It turns out it was something stupid. In the linker step, I was using gcc -Wall -g -lssl -lcrypto -o program program.o
. I needed to move the library links to after the object file I was linking, and put libssl
before libcrypto
:
gcc -Wall -g -o program program.o -lssl -lcrypto
这篇关于在GCC中链接libssl和libcrypto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!