Compile 32 bit MySQL C application on 64 bit Ubuntu

January 21st, 2010 | Tags:

I wrote a small program in C, using MySQL C API. This program was compiled on x86 machine. After a hardware upgrade and installing Ubuntu x64, compiling the program error occurred:

segfault at 1 ip 00007fdcf44f4a29 sp 00007fff19659078 error 4 in libc-2.10.1.so[7fdcf4451000+166000]

After a research in diffrent forums, the solution is:
Install:

sudo apt-get install libc6-dev-i386

Now we need 32 bit version of MySQL development clien library. But there is a small utility, to help install libraries: getlibs. Download getlibs-all from http://frozenfox.freehostia.com/cappy/.

sudo  dpkg -i getlibs-all.deb

32 bit libraries we needed: libmysqlclient-dev and zlib1g-dev.

getlibs -w http://mirrors.kernel.org/ubuntu/pool/main/m/mysql-dfsg-5.1/libmysqlclient-dev_5.1.37-1ubuntu5_i386.deb

The version of MySQL server is:

mysql  Ver 14.14 Distrib 5.1.37, for debian-linux-gnu (x86_64)

And last libruary:

getlibs -w http://mirrors.kernel.org/ubuntu/pool/main/z/zlib/zlib1g-dev_1.2.3.3.dfsg-12ubuntu1_i386.deb



Compiler ( gcc version 4.4.1, x86_64-linux-gnu) command line:

gcc -m32 -c radauth.c -L/usr/lib/mysql -lmysqlclient -lnsl -lm -lz

m32 – 32 bit application
m64 – 64 bit application

No comments yet.