在GCC链接libcrypto [英] Linking libcrypto in GCC
问题描述
好吧,我是pretty知道我在做一些非常愚蠢的,但我似乎无法弄清楚,所以在这里它去。
Okay, I'm pretty sure I'm doing something immensely stupid, but I can't seem to figure it out, so here it goes.
我试图用OpenSSLs EVP废话做一些加密。我是pretty相信我的code是对的,但我似乎无法得到它的编译。我用gcc和安装的libssl-dev的ubuntu的32位precise,并在最新的版本。
I'm attempting to use OpenSSLs EVP crap 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 32bit precise with libssl-dev installed and at the latest version.
目前该项目由一个文件, program.c
。
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.
下面是我如何调用gcc的:
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
下面是的输出找到libcrypto
。我最好的猜测是,这是它的一个愚蠢的位置,这就是为什么我的链接失败,所以我试图 -L / usr / lib目录/ I386-Linux的GNU
在 -lcrypto
没有运气也是如此。
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!
推荐答案
韦尔普。原来这是一些愚蠢的。
Welp. Turns out it was something stupid.
在连接一步,我是用的gcc -Wall -g -lssl -lcrypto -o程序program.o
我需要的对象后,库链接移到文件我是联... 的gcc -Wall -g -o程序program.o -lssl -lcrypto
。
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... gcc -Wall -g -o program program.o -lssl -lcrypto
.
这篇关于在GCC链接libcrypto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!