undefined reference to `SSL_get_current_cipher\' 链接OpenSSL库 -lssl

来源:互联网 发布:天天向上网络 编辑:程序博客网 时间:2024/06/05 18:39

这两天由于工作需要,换了个编译环境,以前是物理机上编译,换到虚拟机上,都是CentOS5.7版本,不知道什么地方不一样,完全相同的工程,换到虚拟机上后链接不过,报错:
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_close_free_options':
(.text+0xd1f): undefined reference to `SSL_CTX_free'
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_get_ssl_cipher':
(.text+0x10b0): undefined reference to `SSL_get_current_cipher'
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_real_connect':
(.text+0x368f): undefined reference to `SSL_get_peer_certificate'
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_real_connect':
(.text+0x36a7): undefined reference to `X509_get_subject_name'
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_real_connect':
(.text+0x36b7): undefined reference to `X509_NAME_oneline'
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_real_connect':
(.text+0x36bf): undefined reference to `X509_free'
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_get_ssl_cipher':
(.text+0x10bc): undefined reference to `SSL_CIPHER_get_name'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `report_errors':
(.text+0x3d): undefined reference to `ERR_get_error_line_data'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `ssl_do':
(.text+0x9a): undefined reference to `SSL_new'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `ssl_do':
(.text+0xaa): undefined reference to `SSL_clear'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `ssl_do':
(.text+0xb2): undefined reference to `SSL_get_session'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `ssl_do':
(.text+0xbd): undefined reference to `SSL_SESSION_set_timeout'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `ssl_do':
(.text+0xc8): undefined reference to `SSL_set_fd'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `ssl_do':
(.text+0xda): undefined reference to `SSL_get_fd'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `ssl_do':
(.text+0x140): undefined reference to `SSL_free'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `sslconnect':
(.text+0x151): undefined reference to `SSL_connect'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `sslaccept':
(.text+0x161): undefined reference to `SSL_accept'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `vio_ssl_close':
(.text+0x196): undefined reference to `SSL_set_quiet_shutdown'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `vio_ssl_close':
(.text+0x19e): undefined reference to `SSL_shutdown'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `vio_ssl_delete':
(.text+0x1dc): undefined reference to `SSL_free'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `vio_ssl_write':
(.text+0x218): undefined reference to `SSL_write'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `vio_ssl_read':
(.text+0x228): undefined reference to `SSL_read'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `report_errors':
(.text+0x3d): undefined reference to `ERR_get_error_line_data'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0xd4): undefined reference to `SSL_CTX_new'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0xf1): undefined reference to `SSL_CTX_set_cipher_list'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x10c): undefined reference to `SSL_CTX_load_verify_locations'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x12d): undefined reference to `SSL_CTX_use_certificate_file'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x14c): undefined reference to `SSL_CTX_use_PrivateKey_file'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x15c): undefined reference to `SSL_CTX_check_private_key'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x169): undefined reference to `DH_new'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x184): undefined reference to `BN_bin2bn'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x199): undefined reference to `BN_bin2bn'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x1c4): undefined reference to `SSL_CTX_ctrl'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x1cc): undefined reference to `DH_free'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x1fe): undefined reference to `SSL_library_init'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x203): undefined reference to `OPENSSL_add_all_algorithms_noconf'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x21c): undefined reference to `SSL_load_error_strings'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x22a): undefined reference to `SSL_CTX_set_default_verify_paths'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x291): undefined reference to `SSL_CTX_free'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x2e6): undefined reference to `DH_free'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x30b): undefined reference to `SSL_CTX_free'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLAcceptorFd':
(.text+0x395): undefined reference to `TLSv1_server_method'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLAcceptorFd':
(.text+0x3cc): undefined reference to `SSL_CTX_ctrl'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLAcceptorFd':
(.text+0x3db): undefined reference to `SSL_CTX_set_verify'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLAcceptorFd':
(.text+0x3eb): undefined reference to `SSL_CTX_set_session_id_context'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLConnectorFd':
(.text+0x44d): undefined reference to `TLSv1_client_method'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLConnectorFd':
(.text+0x48a): undefined reference to `SSL_CTX_set_verify'

查了下,需要链接OpenSSL库,链接参数中加上-lssl后果然链接通过了。但是将执行文件发布到测试机上后,进程启动不了,报错:
error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory

MySQL库等都是静态链接的,想想这个库也应该静态链接的好,否则还得依赖运行环境,而且行为也不可控。于是将libssl改为静态链接,可是怎么尝试静态链接都不行,报错:
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_real_connect':
(.text+0x36a7): undefined reference to `X509_get_subject_name'
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_real_connect':
(.text+0x36b7): undefined reference to `X509_NAME_oneline'
/usr/lib64/mysql/libmysqlclient.a(client.o): In function `mysql_real_connect':
(.text+0x36bf): undefined reference to `X509_free'
/usr/lib64/mysql/libmysqlclient.a(viossl.o): In function `report_errors':
(.text+0x3d): undefined reference to `ERR_get_error_line_data'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `report_errors':
(.text+0x3d): undefined reference to `ERR_get_error_line_data'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x169): undefined reference to `DH_new'

/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x184): undefined reference to `BN_bin2bn'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x199): undefined reference to `BN_bin2bn'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x1cc): undefined reference to `DH_free'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x203): undefined reference to `OPENSSL_add_all_algorithms_noconf'
/usr/lib64/mysql/libmysqlclient.a(viosslfactories.o): In function `new_VioSSLFd':
(.text+0x2e6): undefined reference to `DH_free'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_lib.o): In function `ssl_parse_serverhello_tlsext':
(.text+0x129): undefined reference to `ERR_put_error'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_lib.o): In function `ssl_parse_clienthello_tlsext':
(.text+0x27e): undefined reference to `ERR_put_error'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_lib.o): In function `ssl_add_serverhello_tlsext':
(.text+0x3b8): undefined reference to `ERR_put_error'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_lib.o): In function `ssl_add_clienthello_tlsext':
(.text+0x4f5): undefined reference to `ERR_put_error'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':

(.text+0x132): undefined reference to `EVP_MD_size'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':
(.text+0x13e): undefined reference to `HMAC_CTX_init'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':
(.text+0x146): undefined reference to `HMAC_CTX_init'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':
(.text+0x153): undefined reference to `HMAC_CTX_set_flags'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':
(.text+0x160): undefined reference to `HMAC_CTX_set_flags'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':
(.text+0x176): undefined reference to `HMAC_Init_ex'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':
(.text+0x199): undefined reference to `HMAC_Init_ex'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':
(.text+0x1b3): undefined reference to `HMAC_Update'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libssl.a(t1_enc.o): In function `tls1_P_hash':
(.text+0x1c1): undefined reference to `HMAC_Final'

...
然后增加链接kbr5等各种库,然后又有新的各种undefined,最终也没能静态链接通过...
时间很紧迫,没有继续折腾,就发布动态链接libssl库的版本吧,决定在目标运行机上安装libssl.so.6这个库,执行:
yum -y install libssl.so.6
但纳闷的事情又发生了,明明是64位系统,但是发现yum安装的却是32位的libssl库!拷到lib64目录下,启动进程后,会报libssl.so.6格式错误!

最终时间紧迫,仍然没有找到解决方法。只好发布动态链接libssl的版本,并随发布进程一并提供libssl.so.6和libcrypto.so.6两个动态库,如果目标机器上没有这两个库,就拷到/lib64目录下。

所以遗留下了以下几个问题:
1,同是CentOS5.7的系统,都安装了开发环境,甚至装的MySQL的版本都一样,同样的项目,完全相同的Makefile文件,链接mysql库,为什么在之前的物理机上能链接过,在虚拟机就不能链接过?
2,为什么静态链接libssl链接不过?如果要链接通过,到底还需要链接哪些库?linux和gcc对确定这样的问题,有没有简便的方法?
3,在64位系统上执行yum -y install libssl.so.6安装libssl库,为什么安装的是32位版本?
      对这个问题,网上搜了下答案,如果要安装64位版的libssl.so.6和libssl.so.6,正确的是:
      yum install openssl098e-0.9.8e-18.el6_5.2.x86_64
      下面的命令可以查看库由什么安装包提供的,例如运行下面的命令可以知道libcrypto.so.6是由openssl098e-0.9.8e-18.el6_5.2.x86_64提供的:
      yum whatprovides "*/*libcrypto.so*"

这3个问题记录在这里备忘~如果您知道答案,请给我留言,不甚感激!
0 0
原创粉丝点击