在Ubuntu 11.10中使用gcc编译时对openssl函数的未定义引用 [英] Undefined reference to openssl functions when compiling with gcc in Ubuntu 11.10
本文介绍了在Ubuntu 11.10中使用gcc编译时对openssl函数的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Ubuntu 11.10 x86_64中,我有这个简单的test.c文件:
In Ubuntu 11.10 x86_64 I have this this simple test.c file:
#include <openssl/ssl.h>
int main() {
SSL_library_init();
return 0;
}
为什么用gcc编译失败?
Why does compiling with gcc fail?
$ gcc -lssl -lcrypto test.c
/tmp/ccqL6lRY.o: In function `main':
test.c:(.text+0x5): undefined reference to `SSL_library_init'
collect2: ld returned 1 exit status
使用clang进行编译会产生可运行的可执行文件:
Compiling with clang works and produces a working executable:
$ clang -lssl -lcrypto test.c
$ ldd a.out
linux-vdso.so.1 => (0x00007fffa93e1000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f234a24f000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f2349ea0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2349b00000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f23498fc000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f23496e4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f234a4c4000
推荐答案
尝试将-lssl
放在末尾(在test.c
之后).
Try to put -lssl
at the end (after test.c
).
$ gcc test.c -lssl -lcrypto
这篇关于在Ubuntu 11.10中使用gcc编译时对openssl函数的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文