Bug #22039 error linking to libmysqlclient.so when using MySQL-devel RPM
Submitted: 6 Sep 2006 1:19 Modified: 28 Nov 2008 20:04
Reporter: Alfredo Kojima Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Packaging Severity:S3 (Non-critical)
Version:5.1.11 OS:Linux (Linux RPM based)
Assigned to: Kent Boortz CPU Architecture:Any

[6 Sep 2006 1:19] Alfredo Kojima
Description:
Linking a program to whatever is returned by mysql_config --libs will fail as it
tries to link against libmysqlclient.so et al
Deleting libmysqlclient.la and other .la files in the MySQL libraries directory
solves the problem. 

How to repeat:
Install MySQL-devel-5.1.11-0.glibc23.i386.rpm but not the shared libraries 
package and then try to link something with the MySQL client libs.

Suggested fix:
Move the .la files from the MySQL-devel rpm to the MySQL-shared rpm
[6 Sep 2006 8:10] Sveta Smirnova
Thank you for the report

I have one file bug16300.c connects to database and issues some statements does not matter on 32-bit platform. I used it for tests:

ssmirnova@shella ~/mysql5.1b
$rm ./bug16300

ssmirnova@shella ~/mysql5.1b
$ls -la /users/ssmirnova/mysql5.1b/lib/mysql
total 68608
drwxr-xr-x  2 ssmirnova ssmirnova     4096 Sep  6 10:05 .
drwxr-xr-x  3 ssmirnova ssmirnova     4096 Sep  6 10:05 ..
-rw-r--r--  1 ssmirnova ssmirnova    59242 Jul 28 11:35 ha_archive.a
-rwxr-xr-x  1 ssmirnova ssmirnova      890 Jul 28 11:35 ha_archive.la
-rw-r--r--  1 ssmirnova ssmirnova    38316 Jul 28 11:35 ha_blackhole.a
-rwxr-xr-x  1 ssmirnova ssmirnova      904 Jul 28 11:35 ha_blackhole.la
-rw-r--r--  1 ssmirnova ssmirnova    39280 Jul 28 11:35 ha_example.a
-rwxr-xr-x  1 ssmirnova ssmirnova      890 Jul 28 11:35 ha_example.la
-rw-r--r--  1 ssmirnova ssmirnova    32328 Sep  4 22:53 libdbug.a
-rw-r--r--  1 ssmirnova ssmirnova   539068 Sep  4 22:53 libheap.a
-rw-r--r--  1 ssmirnova ssmirnova  1966568 Sep  4 22:53 libmyisam.a
-rw-r--r--  1 ssmirnova ssmirnova   675574 Sep  4 22:53 libmyisammrg.a
-rw-r--r--  1 ssmirnova ssmirnova  5537844 Sep  4 22:53 libmysqlclient.a
-rwxr-xr-x  1 ssmirnova ssmirnova      969 Sep  4 22:53 libmysqlclient.la
-rw-r--r--  1 ssmirnova ssmirnova  5576996 Sep  4 22:53 libmysqlclient_r.a
-rwxr-xr-x  1 ssmirnova ssmirnova     1023 Sep  4 22:53 libmysqlclient_r.la
-rw-r--r--  1 ssmirnova ssmirnova 45273810 Sep  4 22:54 libmysqld.a
-rw-r--r--  1 ssmirnova ssmirnova  1655306 Sep  4 22:53 libmystrings.a
-rw-r--r--  1 ssmirnova ssmirnova   925088 Sep  4 22:53 libmysys.a
-rw-r--r--  1 ssmirnova ssmirnova  7704898 Sep  4 22:53 libndbclient.a
-rwxr-xr-x  1 ssmirnova ssmirnova     1267 Sep  4 22:53 libndbclient.la
-rw-r--r--  1 ssmirnova ssmirnova    51762 Sep  4 22:54 libvio.a

ssmirnova@shella ~/mysql5.1b
$bin/mysql_config --libs
-L/users/ssmirnova/mysql5.1b/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm

ssmirnova@shella ~/mysql5.1b
$gcc -o bug16300 -lmyodbc3 -L/users/ssmirnova/MyODBC-3.51.11-1-pc-linux-i686/lib -I/users/ssmirnova/include -I/users/ssmirnova/MyODBC-3.51.11-src/test bug16300.c `bin/mysql_config --libs`
In file included from bug16300.c:2:
<a lot of warnings skipped>

ssmirnova@shella ~/mysql5.1b
$./bug16300
 Connecting to 'myodbc3' with user name 'root'...

ssmirnova@shella ~/mysql5.1b
$

So I can not repeat the problem

But if my test is incorrect or if you can provide more information, feel free to add it to this bug and change the status back to 'Open'.
[6 Sep 2006 14:27] Alfredo Kojima
Sorry! Mea culpa. This turned out to be more complicated than I thought, the program must be using libtool for linking (like projects using autoconf with libtool).

a.c contains just:  int main() {}
and link command is:
libtool --tag=CC --mode=link gcc -g -O2  -o foo  a.c `mysql_config --libs`

############ Output with .la files in the libraries directory:

suse1032:~/testme # libtool --tag=CC --mode=link gcc  -g -O2   -o foo  a.c `mysql_config --libs`
gcc -g -O2 -o foo a.c  -L/usr/lib/mysql /usr/lib/mysql/libmysqlclient.so /usr/lib/mysql/libz.so -lpthread -lcrypt -lnsl -lm -Wl,--rpath -Wl,/usr/lib/mysql -Wl,--rpath -Wl,/usr/lib/mysql
gcc: /usr/lib/mysql/libmysqlclient.so: No such file or directory
gcc: /usr/lib/mysql/libz.so: No such file or directory
suse1032:~/testme #

######### Output after deleting *.la from /usr/lib/mysql/:

suse1032:~/testme # rm /usr/lib/mysql/*.la
suse1032:~/testme # libtool --tag=CC --mode=link gcc  -g -O2   -o foo  a.c `mysql_config --libs`
gcc -g -O2 -o foo a.c  -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm
suse1032:~/testme #
[6 Sep 2006 19:42] Sveta Smirnova
Verified as described.

There is workaround to it: use -static or -all-static libtool flags.
[28 Nov 2008 20:04] Trudy Pelzer
Won't fix per MRU criteria.