在链接libmysqlclient的时候,发现出现如下错误:

/usr/lib64/mysql/libz.a(adler32.o)(.text+0x0): In function `adler32':/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/adler32.c:66: multiple definition of `adler32'/usr/lib64/mysql/libmysqlclient.a(adler32.o)(.text+0x0):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/adler32.c:66: first defined here/usr/lib64/mysql/libz.a(adler32.o)(.text+0x340): In function `adler32_combine':/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/adler32.c:138: multiple definition of `adler32_combine'/usr/lib64/mysql/libmysqlclient.a(adler32.o)(.text+0x340):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/adler32.c:138: first defined here/usr/lib64/mysql/libz.a(compress.o)(.text+0x0): In function `compress2':/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/compress.c:28: multiple definition of `compress2'/usr/lib64/mysql/libmysqlclient.a(compress.o)(.text+0x0):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/compress.c:28: first defined here/usr/lib64/mysql/libz.a(compress.o)(.text+0xf0): In function `compress':/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/compress.c:68: multiple definition of `compress'/usr/lib64/mysql/libmysqlclient.a(compress.o)(.text+0xf0):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/compress.c:68: first defined here...



/usr/lib64/mysql/libz.a(inftrees.o)(.text+0x0): In function `inflate_table':


/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/inftrees.c:39: multiple definition of `inflate_table'


/usr/lib64/mysql/libmysqlclient_r.a(inftrees.o)(.text+0x0):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/inftrees.c:39: first defined here


/usr/lib64/mysql/libz.a(trees.o)(.rodata+0x0): In function `init_block':


/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:417: multiple definition of `_length_code'


/usr/lib64/mysql/libmysqlclient_r.a(trees.o)(.rodata+0x0):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:417: first defined here


/usr/lib64/mysql/libz.a(trees.o)(.rodata+0x100): In function `pqdownheap':


/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:459: multiple definition of `_dist_code'


/usr/lib64/mysql/libmysqlclient_r.a(trees.o)(.rodata+0x100):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:459: first defined here


/usr/lib64/mysql/libz.a(trees.o)(.text+0x80): In function `_tr_init':


/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:387: multiple definition of `_tr_init'


/usr/lib64/mysql/libmysqlclient_r.a(trees.o)(.text+0x80):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:387: first defined here


/usr/lib64/mysql/libz.a(trees.o)(.text+0xd20): In function `_tr_align':


/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:894: multiple definition of `_tr_align'


/usr/lib64/mysql/libmysqlclient_r.a(trees.o)(.text+0xd20):/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:894: first defined here


/usr/lib64/mysql/libz.a(trees.o)(.text+0x14b0): In function `_tr_stored_block':


/export/home/my/tmp-200903301116-5.1.34-19266/rpm/BUILD/mysql-5.1.34/zlib/trees.c:872: multiple definition of `_tr_stored_block'


 

从这些信息上看 libmysqlclient_r.a中的一些.o已经在libz.a中定义过了,所以出现了重定义。那么我们只要把其中一个.a文件中重定义过的.o剔除掉就可以了,方法就是:

cp -p /usr/lib64/mysql/libmysqlclient_r.a /usr/lib64/mysql/libmysqlclient_r.a.orig

ar d /usr/lib64/mysql/libmysqlclient_r.a adler32.o compress.o crc32.o deflate.o gzio.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 

 

这代表了一类问题,就是当出现  multiple definition of XXX 的时候都可以采用类似的方法来解决。

 

另外这里有两个特别要注意的地方:

1,lib64,如果安装的是32位版本,静态库可能就会是在/usr/lib64/mysql中。

2,_r,这个是线程安全版本的库的命名方式, 比如目录/usr/lib64/mysql中就有两个libmysqlclient,一个是libmysqlclient.a,还有一个是libmysqlclient_r.a。这个要特别注意,到底是用哪个静态库

​ ​