解决动态链接库中@@OPENSSL_0.9.8符号引起的问题
博客:http://www.cnblogs.com/dzyht/
参考: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
可以指定自己的动态链接库路径;