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

查看:186
本文介绍了使用哪个库? 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:

所以我很困惑为什么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天全站免登陆