libmysqlclient.a is nowhere to be found

房东的猫 提交于 2019-12-22 10:29:32

问题


On an Amazon EC2 (uname -r gives "3.4.37-40.44.amzn1.x86_64", which I hear is based on Cent OS) I tried installing:

yum install mysql
yum install mysql-devel

And even

yum install mysql-libs

(Due to this thread.)

I'm trying to compile a program and link the MySQL libraries to it. This works fine on my Mac, (but the Mac has libmysqlclient.a). libmysqlclient.a is absolutely nowhere to be found on this machine. All it has is libmysqlclient.so, and many versions of it too.

$ sudo find / -name libmysqlclient*

Gives

/usr/lib64/mysql/libmysqlclient_r.so
/usr/lib64/mysql/libmysqlclient.so
/usr/lib64/mysql/libmysqlclient.so.18
/usr/lib64/mysql/libmysqlclient.so.18.0.0
/etc/alternatives/libmysqlclient
/etc/alternatives/libmysqlclient_r

And

ls -l /usr/lib64/mysql

Gives

lrwxrwxrwx 1 root root      34 Apr 11 19:21 libmysqlclient_r.so -> /etc/alternatives/libmysqlclient_r
lrwxrwxrwx 1 root root      32 Apr 11 19:21 libmysqlclient.so -> /etc/alternatives/libmysqlclient
lrwxrwxrwx 1 root root      24 Apr 11 18:24 libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
-rwxr-xr-x 1 root root 2983360 Mar 14 10:09 libmysqlclient.so.18.0.0
-rwxr-xr-x 1 root root   11892 Mar 14 09:12 mysqlbug
-rwxr-xr-x 1 root root    7092 Mar 14 10:08 mysql_config

So the only real file is libmysqlclient.so.18.0.0.

The compiler command:

g++ main.cpp -L/usr/lib64/mysql -lmysqlclient.so.18.0.0

Fails with

/usr/bin/ld: cannot find -lmysqlclient.so.18.0.0
collect2: ld returned 1 exit status

So somebody is lying or I got completely ripped off at the YUM repo and was not given my libmysqlclient.a like I was supposed to.

(I avoided using the many symlinks on the system so I could eliminate possible issues).


回答1:


bobobobo! You are so wrong.

First of all, you don't need a libmysqlclient.a file, when you have the .so file. The .a file is for static linking, .so file for dynamic linking.. .so files are decidely better and make you cool.

The problem you get when you try and compile without library link is

g++ main.cpp

Gives

undefined reference to `mysql_init'

But that can be fixed with

g++ main.cpp `mysql_config --cflags --libs`



回答2:


explain: ".so files are decidely better and make you cool.", please. looking at agner fogs manual, .a libraries are, looking at performance level, even better. You don't need to load a library into memory when you just need 2 or 3 functions from it...




回答3:


When you use .so, they are linked a run-time. This makes your compiled code smaller. Not usually big deal these days. The really great feature is that when you update your system, and the library gets updated, you will link in the new (and hopefully) better library. The updates often contain bug fixes and security fixes. Possibly performance improvements. Therefore they make your code more cool and, indirectly, make you a little bit more cool.



来源:https://stackoverflow.com/questions/15958612/libmysqlclient-a-is-nowhere-to-be-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!