How to make Mac OS X and MySQL happy with Qt

Using shared libraries on Mac OS X is one of the things that is actually a lot harder than on Windows.  For example, you cannot just put the shared library for MySQL into your path or into the working directory. You have to change the plugin file itself to make it look in the correct location. You find the current value using the command “otool” and change the value using the command “install_name_tool”. Here is an example:

cd Qt/5.4/clang_64/plugins/sqldrivers/

otool -L libqsqlmysql.dylib 

libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
...

install_name_tool -change /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.20.dylib ./libqsqlmysql.dylib 

otool -L libqsqlmysql.dylib 

libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/mysql/lib/libmysqlclient.20.dylib (compatibility version 18.0.0, current version 18.0.0)
...

Author: sirspot

I write software, love my wife and kids, do various house projects, play video games when I have time, and could use a little more sleep