I want to thank to Cameron Chenier for writting this guide in first place. I found it very helpful and wanted to share it in my site.
C program interfacing with MySQL by Cameron Chenier (cameron.chenier@cameronchenier.com)
The following is required when compiling a c program that requires a link to a mysql database all on a Windows machine. There are other ways of accomplishing this task. This method will use cygwin in order to use gcc. A libmysqlclient is used to connect to the database. However cygwin must compile this file from the source code of mysql, or we'll have problems with it. So what we have is Mysql installed on the Windows machine using the Windows Binaries from the mysql.org website. In order to get the libmysqlclient.a we must compile the mysql source code (NOT the Windows code) using gcc through cygwin. Following the steps below assumes you have Mysql server install on a windows machine. Cygwin is installed with the gcc, g++, and make packages.
#include <mysql.h>
int main() {
MYSQL conn;
return 0;
}
-I/usr/local/include/mysql -L/usr/local/lib/mysql -lmysqlclient
gcc test.c -o test -I/usr/local/include/mysql -L/usr/local/lib/mysql \ -lmysqlclient
/usr/local/lib/mysql/libmysqlclient.a(my_compress.o):my_compress.c:(.text+0x5e): undefined reference to "_compress"
gcc test.c -o test /cygdrive/c/mysql-src/mysql-4.1.16/libmysql/my_compress.o
If you've found this to be an useful document, don't forget to share it.