Bug #59006 client library has incorrect paths embedded
Submitted: 17 Dec 2010 19:21 Modified: 24 May 2017 10:57
Reporter: Alfredo Kojima Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Packaging Severity:S2 (Serious)
Version:5.5.8 OS:MacOS
Assigned to: CPU Architecture:Any
Tags: regression

[17 Dec 2010 19:21] Alfredo Kojima
Description:
libmysqlclient shipped with MySQL 5.5.8 (and probably before) has incorrect path embedded, which makes programs linked to it to crash on start (as you can see in repeat instructions).

How shared lib id name looked like for libmysqlclient in MySQL 5.1:

kojima@Woodstock tmp$ otool -DX /usr/local/mysql-5.1.50-osx10.6-x86/lib/libmysqlclient.dylib
/usr/local/mysql/lib/libmysqlclient.16.dylib

How it is now:

kojima@Woodstock lib$ otool -DX /usr/local/mysql-5.5.8-osx10.6-x86/lib/libmysqlclient.dylib/
libmysqlclient.16.dylib

This can be worked around by the user with:
kojima@Woodstock lib$ sudo install_name_tool -id /usr/local/mysql/lib/libmysqlclient.16.dylib libmysqlclient.dylib/
Password:
kojima@Woodstock lib$ otool -DX /usr/local/mysql-5.5.8-osx10.6-x86/lib/libmysqlclient.dylib/
/usr/local/mysql/lib/libmysqlclient.16.dylib

But obviously build scripts should be fixed so that this isn't necessary.

How to repeat:
Anyone trying to compile something with mysql 5.5 client lib will first face bug #51925 Once that is manually fixed/workarounded, create a trivial a.cc file containing:

#include <mysql.h> 
int main() {}

Then:

kojima@Woodstock tmp$ ls -ld /usr/local/mysql
lrwxr-xr-x 1 root wheel 24 Dec 17 16:03 /usr/local/mysql -> mysql-5.5.8-osx10.6-x86//
kojima@Woodstock tmp$ g++ a.cc `/usr/local/mysql/bin/mysql_config --cflags --libs`
kojima@Woodstock tmp$ ./a.out
dyld: Library not loaded: libmysqlclient.16.dylib
  Referenced from: /private/tmp/./a.out
  Reason: image not found
Trace/BPT trap

In contrast, this is how it used to work with MySQL 5.1:

kojima@Woodstock tmp$ ls -ld /usr/local/mysql
lrwxr-xr-x 1 root wheel 25 Dec 17 15:50 /usr/local/mysql -> mysql-5.1.50-osx10.6-x86//
kojima@Woodstock tmp$ g++ a.cc `/usr/local/mysql/bin/mysql_config --cflags --libs`
kojima@Woodstock tmp$ ./a.out

After applying workaround on 5.5 client lib:
kojima@Woodstock tmp$ ls -ld /usr/local/mysql
lrwxr-xr-x 1 root wheel 24 Dec 17 16:03 /usr/local/mysql -> mysql-5.5.8-osx10.6-x86//
kojima@Woodstock tmp$ g++ a.cc `/usr/local/mysql/bin/mysql_config --cflags --libs`
kojima@Woodstock tmp$ ./a.out

Suggested fix:
Change id name of client lib.
[17 Dec 2010 19:25] Alfredo Kojima
Forgot to mention, but this is Mac OS X specific.
[18 Dec 2010 8:43] Valeriy Kravchuk
Indeed:

macbook-pro:5.5-sec openxs$ otool -DX /usr/local/mysql-5.1.53-osx10.5-x86_64/lib/libmysqlclient.dylib 
/usr/local/mysql/lib/libmysqlclient.16.dylib
macbook-pro:5.5-sec openxs$ otool -DX /usr/local/mysql-advanced-5.5.8-osx10.5-x86_64/lib/libmysqlclient.dylib 
libmysqlclient.16.dylib

I think this is cmake/packaging problem
[6 Feb 2011 5:30] David Phillips
To summarize, this is the command to run to fix the problem:

sudo install_name_tool -id \
/usr/local/mysql/lib/libmysqlclient.16.dylib \
/usr/local/mysql/lib/libmysqlclient.dylib
[7 Apr 2011 17:12] Sierk Bornemann
Also see:

CPAN Bug #65462 for DBD-mysql: Compiling DBD:mysql on Mac OS X 10.6.6 fails
https://rt.cpan.org/Public/Bug/Display.html?id=65462#txn-916407

Problems installing DBD::mysql on OS X Snow Leopard
http://probably.co.uk/problems-installing-dbdmysql-on-os-x-snow-leopard.html

Library not loaded: libmysqlclient.16.dylib error when trying to run 'rails server' on OS X 10.6 with mysql2 gem
http://stackoverflow.com/questions/4546698/library-not-loaded-libmysqlclient-16-dylib-erro...

They all seem to have the same cause and could be fixed with the same solution:
include the library's search path in the compiled binary.
[3 Jul 2012 22:49] Alfredo Kojima
This is still a problem in 5.2.24
The following bugs are duplicates as far as I can see: bug #61243 bug #61699
[21 Oct 2013 10:44] Sierk Bornemann
Still an issue on MySQL 5.6.x and MySQL 5.7.x.

When will it be finally fixed?
[24 May 2017 10:57] Erlend Dahl
Duplicate of

Bug#61243 lib/libmysqlclient.18.dylib is broken on Mac OS X