openssl动态库编译
通常Linux系统自带OpenSSL,但是其so文件由于没有debug信息,因此无法跟踪内部函数,对于学习
不太方便,需要通过源码重新安装。
我的Linux系统是CentOS7,自带的OpenSSL的版本是1.0.1e。在网上下载了OpenSSL1.0.1f后,通过
如下方法安装
- ./config --prefix=/usr/local --openssldir=/usr/local/ssl
- make && make install
- ./config -d shared --prefix=/usr/local --openssldir=/usr/local/ssl
- make clean
- make && make install
先安装静态库版本,再安装动态库版本。安装目录为/usr/local下。安装动态库时增加-d选项,因为
调试时使用动态库,需要跟踪代码。
这样后面就可以写调试代码调试,如下面的例子:
#include <stdio.h>#include <string.h>#include <openssl/bio.h>int main(){BIO *b = NULL;int len = 0;char *out = NULL;b = BIO_new(BIO_s_mem()); if (NULL == b){return 0;} len = BIO_write(b,"openssl",4);len = BIO_printf(b,"%s","zcp");len = BIO_ctrl_pending(b); out = (char *)OPENSSL_malloc(len);if (NULL == out){return 0;}memset(out, 0, len);len = BIO_read(b,out,len);printf("out is : %s\n",out); OPENSSL_free(out);BIO_free(b);return 0;} 在当前路径下创建一个新的动态库软链接:
ln -s /usr/local/lib64/libcrypto.so.1.0.0 libcrypto.so.10
然后gcc编译时指明使用这个libcrypto:
gcc -g -DDEBUG -o openssl_mem_bio_test openssl_mem_bio_test.c -lcrypto -Wl,-rpath=.
浙公网安备 33010602011771号