This question already has an answer here:
这个问题在这里已有答案:
- Errors that refer to a bunch of unresolved OpenSSL symbols that clearly exist? 1 answer
引用一堆明显存在的未解决的OpenSSL符号的错误? 1个答案
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.
我正在尝试使用OpenSSL的EVP接口进行一些加密。我很确定我的代码是正确的,但我似乎无法编译它。我正在使用GCC,并且安装了libssl-dev的Ubuntu 32位精确版和最新版本。
The project currently consists of one file, program.c
.
该项目目前包含一个文件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:
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.
这是locate libcrypto的输出。我最好的猜测是,这是一个愚蠢的位置,这就是我的链接失败的原因,所以我在-lcrypto之前尝试了-L / usr / lib / i386-linux-gnu,但也没有运气。
/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!
我有点难过。如果有人想让我觉得自己像个傻瓜,我会非常兴奋地弄清楚我做错了什么!
2 个解决方案
#1
12
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 -lssl -lcrypto -o program program.o。我需要将库链接移动到我链接的目标文件之后,并将libssl放在libcrypto之前:
gcc -Wall -g -o program program.o -lssl -lcrypto
#2
-1
Try including headers using -I option, Look into directory for library using -L and finally specifying the library name with -l
尝试使用-I选项包含标题,使用-L查看库的目录,最后使用-l指定库名
Just making guess here, please specify path based on actual location.
在这里猜猜,请根据实际位置指定路径。
gcc -g -Wall -L/usr/lib -I/usr/include -lssl -lcrypto -o program program.c
Hope it may help.
希望它可能有所帮助。
#1
12
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 -lssl -lcrypto -o program program.o。我需要将库链接移动到我链接的目标文件之后,并将libssl放在libcrypto之前:
gcc -Wall -g -o program program.o -lssl -lcrypto
#2
-1
Try including headers using -I option, Look into directory for library using -L and finally specifying the library name with -l
尝试使用-I选项包含标题,使用-L查看库的目录,最后使用-l指定库名
Just making guess here, please specify path based on actual location.
在这里猜猜,请根据实际位置指定路径。
gcc -g -Wall -L/usr/lib -I/usr/include -lssl -lcrypto -o program program.c
Hope it may help.
希望它可能有所帮助。