结论就是:
mysql提供的静态库,没有加-fPIC选项,导致DBD编译失败
解决:
1. 加fPIC,重新编译libmysqlclient.a
2. 使用动态库
Description: I am trying to compile the DBD::mysql perl module on an x86_64 platform and I get the following errors: [some stuff cut out here] rm -f blib/arch/auto/DBD/mysql/mysql.so LD_RUN_PATH="/usr/lib" /usr/bin/perl myld cc -shared -L/usr/local/lib dbdimp.o mysql.o -o blib/arch/auto/DBD/mysql/mysql.so \ -L/usr/local/mysql/lib -lmysqlclient -lcrypt -lnsl -lm -lz \ /usr/bin/ld: /usr/local/mysql/lib/libmysqlclient.a(libmysql.o): relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC /usr/local/mysql/lib/libmysqlclient.a: could not read symbols: Bad value collect2: ld returned 1 exit status chmod 755 blib/arch/auto/DBD/mysql/mysql.so chmod: cannot access `blib/arch/auto/DBD/mysql/mysql.so': No such file or directory make: *** [blib/arch/auto/DBD/mysql/mysql.so] Error 1 After a couple of days of digging around, this is what I've found: 1. If only static libraries are provided, they should be compiled with -fPIC on the x86_64 platform (this is different from regular x86). This allows other people to create their own shared libraries from your static libraries by linking against them, which is what DBD::mysql is trying to do with libmysqlclient.a. I found this information at http://www.x86-64.org/lists/discuss/msg05760.html -- even though it is not about mysql, it is about this specific linker error. 2. This same bug was filed under Mysql Bug #4670, which was closed with a work around listed (complile a dynamic libmysqlclient library and link against that instead). I believe that it is still a bug, however, because only a workaround is listed--the actual fix would be to link all static libraries for x86_64 platforms with -fPIC. I will attempt to compile my own libmysqlclient with -fPIC, but it would save a lot of headaches for other people if they came compiled that way with the binary distributions. How to repeat: Try to compile DBD::mysql on an x86_64 platform with static mysql libraries (no dynamic libraries were provided with the binary distributions) Suggested fix: Begin compiling static libraries (specifically libmysqlclient.a) with -fPIC on the x86_64 platform or provide dynamic libraries in addition to the static libraries.