Bug #61243 lib/libmysqlclient.18.dylib is broken on Mac OS X
Submitted: 20 May 2011 13:17 Modified: 5 Feb 2014 1:32
Reporter: Yoshisuke TATEYAMA Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:5.5.12 OS:MacOS (Mac OS X 10.6.7, XCode 3.2.6)
Assigned to: CPU Architecture:Any
Tags: mac

[20 May 2011 13:17] Yoshisuke TATEYAMA
Description:
When I try to make a executable file (a.out) linking  /usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib in the binary package: mysql-5.5.12-osx10.6-x86_64.dmg, the a.out dumps core.

How to repeat:
Install from the binary package: mysql-5.5.12-osx10.6-x86_64.dmg, and do followings on Terminal.app.

$ otool -L /usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib 
/usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib:
	libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)

$ cat test.c
main() {printf("hello\n");}
$ gcc test.c /usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.dylib
$ ./a.out 
dyld: Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/yoshi/mysql-ruby/./a.out
  Reason: image not found
Trace/BPT trap (core dumped)
$ otool -L a.out
.out:
	libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
$

Suggested fix:
The shared library file: /usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib must contain full path id.
A dirty hack might be the followings:

$ sudo install_name_tool -id /usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib /usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib

Then we can get a correct libmysqlclient.dylib!

$ otool -L /usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib 
/usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib:
	/usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)
$ gcc test.c /usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.dylib 
$ ./a.out 
hello
$ otool -L ./a.out 
./a.out:
	/usr/local/mysql-5.5.12-osx10.6-x86_64/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
$ 

But basically, you must make a definition of the cmake macro "MERGE_LIBRARIES" in "mysql-5.5.12/cmake/libutils.cmake" work correctly in Mac OS X.
cmake seems to be able to create correct shared libraries simply using ADD_LIBRARY.
[20 May 2011 14:32] Yoshisuke TATEYAMA
libmysqlclient.16.dylib in MySQL Version 5.1.57 is good (if it installed in /usr/local/mysql/lib).

$ otool -L mysql-5.1.57-osx10.6-x86_64/lib/libmysqlclient.16.dylib 
mysql-5.1.57-osx10.6-x86_64/lib/libmysqlclient.16.dylib:
	/usr/local/mysql/lib/libmysqlclient.16.dylib (compatibility version 17.0.0, current version 17.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)
[21 May 2011 8:41] Valeriy Kravchuk
Verified on Mac OS X 10.5.x also. Version 5.5.10 had the same problem it seems (unlike 5.1.x).
[24 Jul 2011 15:37] Paul Wellens
I verified this on 5.5.14 and the same problem/solution is valid there. This turned out to be the final obstacle that I needed to removed to succesfully compile, install and use DBD::mysql on Mac OS X 10.6
so I can access a Mysql database from e Perl script. There are many reports on the Internet about problems getting that to work. It is far from obvious that this is one of the causes until , of course you analyze the error message one more time.

Dozo arigato!
[21 Oct 2013 10:43] Sierk Bornemann
Still an issue on MySQL 5.6.x and MySQL 5.7.x.

When will it be finally fixed?
[5 Feb 2014 1:32] Paul DuBois
Noted in 5.7.4 changelog.

On Mac OS X, the libmysqlclient dylib file linked to itself.
[24 May 2017 10:58] Erlend Dahl
Bug#59006 client library has incorrect paths embedded

was marked as a duplicate