解决动态链接库中@@OPENSSL_0.9.8符号引起的问题

随笔 - 6  文章 - 0  评论 - 0

解决动态链接库中@@OPENSSL_0.9.8符号引起的问题

作者:dzygogo@gmail.com
博客:http://www.cnblogs.com/dzyht/   
 
本文的copyleft归dzygogo@gmail.com所有,使用GPL发布,可以自由拷贝,转载。但转载请保持文档的完整性,注明原作者及原链接,严禁用于任何商业用途。
==============================================================

参考:http://forums.gentoo.org/viewtopic-t-835256-start-0.html

 通常编译时提示:

/usr/lib/libcrypto.so.0.9.8: version `OPENSSL_0.9.8' not found

/usr/lib/libssl.so.0.9.8: version `OPENSSL_0.9.8' not found

或者提示类似“X509_STORE_CTX_init@@OPENSSL_0.9.8”找不到,根本原因是动态链接库编译的时候需要添加version信息。

比如添加了version信息,编译后的so动态库里面的函数名应该是形如:

复制代码
X509_EXTENSION_free@@OPENSSL_0.9.8
X509_NAME_cmp@@OPENSSL_0.9.8
X509_NAME_dup@@OPENSSL_0.9.8
X509_NAME_free@@OPENSSL_0.9.8
X509_STORE_CTX_cleanup@@OPENSSL_0.9.8
X509_STORE_CTX_get0_param@@OPENSSL_0.9.8
X509_STORE_CTX_get_ex_new_index@@OPENSSL_0.9.8
X509_STORE_CTX_init@@OPENSSL_0.9.8
X509_STORE_CTX_set_default@@OPENSSL_0.9.8
X509_STORE_CTX_set_ex_data@@OPENSSL_0.9.8
X509_STORE_CTX_set_verify_cb@@OPENSSL_0.9.8
X509_STORE_free@@OPENSSL_0.9.8
X509_STORE_get_by_subject@@OPENSSL_0.9.8
X509_STORE_load_locations@@OPENSSL_0.9.8
复制代码

而不是:

复制代码
 U X509_EXTENSION_free
         U X509_NAME_cmp
         U X509_NAME_dup
         U X509_NAME_free
         U X509_STORE_CTX_cleanup
         U X509_STORE_CTX_get0_param
         U X509_STORE_CTX_get_ex_new_index
         U X509_STORE_CTX_init
         U X509_STORE_CTX_set_default
         U X509_STORE_CTX_set_ex_data
         U X509_STORE_CTX_set_verify_cb
         U X509_STORE_free
         U X509_STORE_load_locations
         U X509_STORE_new
         U X509_STORE_set_default_paths
         U X509_VERIFY_PARAM_free
         U X509_VERIFY_PARAM_get_depth
复制代码

针对openssl-0.9.8l,补丁如下:

 

diff -Nur openssl-0.9.8l/Configure openssl-0.9.8l-work-new/Configure
--- openssl-0.9.8l/Configure 2009-11-05 20:07:06.000000000 +0800
+++ openssl-0.9.8l-work-new/Configure 2013-06-07 14:40:17.150133355 +0800
@@ -1434,6 +1434,8 @@
$shlib_minor=$2;
}

+$shared_ldflag .= " -Wl,--version-script=openssl.ld";
+
open(IN,'<Makefile.org') || die "unable to read Makefile.org:$!\n";
unlink("$Makefile.new") || die "unable to remove old $Makefile.new:$!\n" if -e "$Makefile.new";
open(OUT,">$Makefile.new") || die "unable to create $Makefile.new:$!\n";
diff -Nur openssl-0.9.8l/engines/openssl.ld openssl-0.9.8l-work-new/engines/openssl.ld
--- openssl-0.9.8l/engines/openssl.ld 1970-01-01 08:00:00.000000000 +0800
+++ openssl-0.9.8l-work-new/engines/openssl.ld 2013-06-07 14:40:37.301575058 +0800
@@ -0,0 +1,4 @@
+OPENSSL_0.9.8 {
+ global:
+ *;
+};
diff -Nur openssl-0.9.8l/openssl.ld openssl-0.9.8l-work-new/openssl.ld
--- openssl-0.9.8l/openssl.ld 1970-01-01 08:00:00.000000000 +0800
+++ openssl-0.9.8l-work-new/openssl.ld 2013-06-07 14:40:25.556574659 +0800
@@ -0,0 +1,4 @@
+OPENSSL_0.9.8 {
+ global:
+ *;
+};

 这个patch上传到了:

http://files.cnblogs.com/dzyht/dzy.zip

解压后给openssl-0.9.8l打补丁:

跟openssl-0.9.8l同一级目录下执行以下程序:

[root@ openssl]# patch -p0<dzy.patch
patching file openssl-0.9.8l/Configure
patching file openssl-0.9.8l/engines/openssl.ld
patching file openssl-0.9.8l/openssl.ld

 

另外:参考《程序员的自我修养:链接、装载与库》8.5,两个小技巧:

1.LD_DEBUG=all ./app_main

这个可也以看到很多链接加载信息;

2.LD_LIBRARY_PATH=../lib ./app_main

可以指定自己的动态链接库路径;

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页