Libmysqlclient.a not found anywhere

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

 yum install mysql yum install mysql-devel 

And even

 yum install mysql-libs 

(Because of this stream .)

I am trying to compile a program and link MySQL libraries to it. This works fine on my Mac (but the Mac has libmysqlclient.a ). libmysqlclient.a absolutely nowhere to be found on this machine. All he 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 

Thus, the only real file is libmysqlclient.so.18.0.0 .

Compiler command:

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

Crash with

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

So, someone is lying, or I am completely ripped off in a YUM replica, and they have not given me my libmysqlclient.a , as I expected.

(I avoided using many symbolic links in the system so that I could fix possible problems).

+3
source share
3 answers

bobobobo! You are so unfaithful .

First of all, you do not need the libmysqlclient.a file if you have a .so file. The .a file is designed to statically link the .so file for dynamic linking. ..so files are much better and make you cool.

The problem that occurs when trying to compile without a link to the library,

 g++ main.cpp 

gives

 undefined reference to `mysql_init' 

But which can be fixed with

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

explain: ". files are too rare and make you cool." please. looking at the agner fogs, .a library manual, looking at the performance level, is even better. You do not need to load the library into memory when you just need 2 or 3 functions ...

+2
source

When you use .so, they are bound by runtime. This will reduce your compiled code. These days, usually not so much. A great feature is that when you upgrade your system and update the library, you will reference the new (and, hopefully) better library. Updates often contain bug fixes and security fixes. Performance improvements are possible. Therefore, they make your code cooler and, indirectly, make you a little cooler.

0
source

Source: https://habr.com/ru/post/1308962/


All Articles