libmysqlclient.a无处可查 [英] libmysqlclient.a is nowhere to be found

查看:368
本文介绍了libmysqlclient.a无处可查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Amazon EC2上( uname -r 给出了3.4.37-40.44.amzn1.x86_64,我听说它基于Cent OS)我尝试安装:

  yum install mysql 
yum install mysql-devel

甚至

  yum install mysql-libs 

(由于 this thread 。)



我试图编译一个程序并将MySQL库链接到它。这适用于我的Mac,<但> Mac libmysqlclient.a )。 libmysqlclient.a 在这台机器上绝对找不到。它的所有内容都是 libmysqlclient.so 以及它的许多版本。

  $ sudo find / -name libmysqlclient * 

给出

  /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





$ ls -l / usr / lib64 / mysql

给出

  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



<因此,唯一真正的文件是 libmysqlclient.so.18.0.0



编译器命令:

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



$ p
$ b $ p $ / usr / bin / ld:找不到-lmysqlclient.so.18.0.0
collect2:ld返回1退出状态

所以有人说谎,或者我在YUM仓库中被彻底扯掉,没有像我应该给我的 libmysqlclient.a 那样。



(我避免在系统上使用很多符号链接,这样我就可以消除可能的问题)。

解决方案

bobobobo!您是错的首先,当您有.so文件时,您不需要libmysqlclient.a文件。 .a文件用于静态链接,.so文件用于动态链接。 。 .so文件确实更好,让你更酷。



当您尝试编译时没有库链接时,您遇到的问题是:

  g ++ main.cpp 

给出

 对`mysql_init'的未定义引用

可以通过修复

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


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).

解决方案

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`

这篇关于libmysqlclient.a无处可查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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