使用哪个库?libmariadbclient 还是 libmysqlclient? [英] Which lib to use? libmariadbclient or libmysqlclient?

查看:25
本文介绍了使用哪个库?libmariadbclient 还是 libmysqlclient?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知什么原因,我的 libmysqlclient.a 在我的 CentOS 7 中消失了.然后我的程序出现链接器错误,说找不到 libmysqlclient.

For some unknown reason, my libmysqlclient.a disappeared in my CentOS 7. My program then got linker error, saying cannot find libmysqlclient.

然后我发现我的 mysql-devel 包不见了:

And then I discovered that my mysql-devel package is gone:

yum info mysql-devel
yum install mysql-devel

回复如下:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: repo.virtualhosting.hk
 * epel: mirror.pregi.net
 * extras: repo.virtualhosting.hk
 * updates: repo.virtualhosting.hk
Package MariaDB-devel-10.2.5-1.el7.centos.x86_64 already installed and latest version

所以我想也许我应该改用 libmariadbclient,但是当我将我的程序与 libmariadbclient 链接时,它出现了链接错误:

So I think maybe I should use libmariadbclient instead, but when I link my program with libmariadbclient, it had linking errors:

/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x191): undefined reference to `CRYPTO_num_locks'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1aa): undefined reference to `CRYPTO_THREADID_set_callback'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1b6): undefined reference to `CRYPTO_set_locking_callback'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1bb): undefined reference to `SSL_library_init'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1c7): undefined reference to `SSL_load_error_strings'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1cc): undefined reference to `OPENSSL_add_all_algorithms_noconf'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x2b4): undefined reference to `CRYPTO_set_locking_callback'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x2bb): undefined reference to `CRYPTO_set_id_callback'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x2df): undefined reference to `CRYPTO_num_locks'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x340): undefined reference to `EVP_cleanup'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x345): undefined reference to `CRYPTO_cleanup_all_ex_data'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x34a): undefined reference to `ERR_free_strings'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x351): undefined reference to `CONF_modules_free'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `ma_tls_init':
(.text+0x3e1): undefined reference to `SSLv23_client_method'
/usr/lib64//libmariadbclient.a(openssl.c.o): In function `my_cb_threadid':
(.text+0x1e): undefined reference to `CRYPTO_THREADID_set_numeric'
/usr/lib64//libmariadbclient.a(ma_compress.c.o): In function `_mariadb_compress_alloc':
(.text+0x5d): undefined reference to `compress'
/usr/lib64//libmariadbclient.a(ma_compress.c.o): In function `_mariadb_uncompress':
(.text+0x191): undefined reference to `uncompress'
collect2: error: ld returned 1 exit status

我一直在使用 libmysqlclient 连接我的 MariaDB 10.1,最近一直在尝试从源代码构建它,但由于 OpenSSL 1.1 版本的问题而失败.在这里你可以看到我的另一篇文章:

I've been using libmysqlclient to connect with my MariaDB 10.1, and have recently been trying to build it from source, but failed due to problems with OpenSSL 1.1 version. Here you see my another post for it:

错误MD5_CONTEXT 类型不完整";使用 MariaDB 10.2 和 Openssl 1.1.0e

所以我很困惑为什么 mysqlclient.a 消失了,我应该使用哪个库.

So I'm confused why mysqlclient.a disappeared and which lib I should use.

谁能帮忙?

谢谢!

推荐答案

我在尝试使用-lmariadbclient"编译我的程序时遇到了类似的问题(apt-get update -lmysqlclient 停止工作).我使用的 Makefile 是:

I had the similar problem when tried to compile my program with "-lmariadbclient" (after apt-get update -lmysqlclient stopped working). The Makefile I used was:

g++ -std=c++11 *.cpp ../common/*.cpp ../common/*.c -o myprogram -I.. -ldl -Wstack-protector -fstack-protector-all -pthread -ggdb -lssl -lcrypto -lz -lmariadbclient -Wwrite-strings  -fPIC 

我读到必须添加命令-lssl -lcrypto -lz"来修复这些错误,但我把它们放在了错误的位置(在 lmariadbclient 之前).当我在-lmariadbclient"之后添加它们时,我终于能够编译我的程序了:

I read that commands "-lssl -lcrypto -lz" must be added to fix those errors, but I put them in the wrong place (before lmariadbclient). When I added them after "-lmariadbclient" I was finally able to compile my program:

g++ -std=c++11 *.cpp ../common/*.cpp ../common/*.c -o myprogram -I.. -ldl -Wstack-protector -fstack-protector-all -pthread -ggdb -lmariadbclient -Wwrite-strings -lssl -lcrypto -lz -fPIC 

22.07.2017 更新:

我最近尝试在新的 Linux Mint 18.2 上编译我的程序.不幸的是,我遇到了同样的编译错误,我无法用旧方法修复它:

I recently tried to compile my program on the new Linux Mint 18.2. Unfortunately I was getting the same compilation errors, and I was unable to fix it with the old method:

MariaDB 版本:

MariaDB version:

 mysql --version
 mysql  Ver 15.1 Distrib 10.2.7-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

编译错误:

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x189): undefined reference to `CRYPTO_num_locks'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1a4): undefined reference to `CRYPTO_THREADID_set_callback'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1b0): undefined reference to `CRYPTO_set_locking_callback'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1b5): undefined reference to `SSL_library_init'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1c1): undefined reference to `SSL_load_error_strings'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_start':
(.text+0x1c6): undefined reference to `OPENSSL_add_all_algorithms_noconf'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x2a4): undefined reference to `CRYPTO_set_locking_callback'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x2ab): undefined reference to `CRYPTO_set_id_callback'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x2cf): undefined reference to `CRYPTO_num_locks'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x330): undefined reference to `EVP_cleanup'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x335): undefined reference to `CRYPTO_cleanup_all_ex_data'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x33a): undefined reference to `ERR_free_strings'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_end':
(.text+0x33f): undefined reference to `CONF_modules_free'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `ma_tls_init':
(.text+0x3c1): undefined reference to `SSLv23_client_method'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libmariadbclient.a(openssl.c.o): In function `my_cb_threadid':
(.text+0x1e): undefined reference to `CRYPTO_THREADID_set_numeric'

我设法通过将-lmariadbclient"更改为:-lmariadb"来修复它.之后,我能够毫无错误地编译我的程序.我不确定这个解决方案是否适用于所有人,但值得一试:)

I managed to fix it by changing "-lmariadbclient" to: "-lmariadb". After that I was able to compile my program with no errors. I'm not sure if this solution will work for everyone, but worth to try :)

我最终的 Makefile 是:

My final Makefile is:

g++ -std=c++11 *.cpp ../common/*.cpp ../common/*.c -o myprogram -I.. -ldl -Wstack-protector -fstack-protector-all -pthread -ggdb -lmariadb -Wwrite-strings -lssl -lcrypto -lz -fPIC 

祝你好运!

这篇关于使用哪个库?libmariadbclient 还是 libmysqlclient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆