brianmario/mysql2 — pull request #412 by davidzhao (2013-07-26 07:33:37+00:00)
Title: 0.3.13 could not load at runtime when libmysqlclient.so is installed to non standard location

When MySQL is installed to a non-standard location, mysql2 builds fine but could not find the library at runtime. In my case, MySQL server was installed to /opt/mysql/server-5.6

$ ldd mysql2.so
linux-vdso.so.1 => (0x00007fff9dbff000)
libmysqlclient.so.18 => not found
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9932de4000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9932a24000)
/lib64/ld-linux-x86-64.so.2 (0x00007f993321a000)

This patch fixes it by adding rpath to gcc linker flags.

$ ldd mysql2.so
linux-vdso.so.1 => (0x00007ffffabf9000)
libmysqlclient.so.18 => /opt/mysql/server-5.6/lib/libmysqlclient.so.18 (0x00007f62a2707000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f62a24e0000)
...