This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Mysql client through gcc under cygwin


Hello All,
I had a though time programing a mysql client using gcc through cygwin. I
have come up with a guide which I hope will help anyone trying to
accomplish this in the future. There are other sites with advise out
there, but I was unable to find one that took me from start to finish.
Thus I have put this information together.



Windows 2k3 Server / CYGWIN / C program interfacing w/ mysql
Cameron Chenier (cameron.chenier@cameronchenier.com)

Completed Using:
mysql version 4.1.16
cygwin 1.5.18

Prereq:
Windows Installed
Mysql Installed using Windows Binaries (This is separate from the cygwin
mysql install)
Cygwin installed with gcc, g++, make

Overview:
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.

Steps:

   1.
      Download source for mysql from www.mysql.org
      -Get the linux source (tar.gz). This is at the end of the download
webpage
   2.
      Untar mysql source (ex. C:\mysql-src)
   3.
      Open cygwin
   4.
      Configure mysql install. Do this with â??without-server option
         1.
            %>cd /cygdrive/c/mysql-src/mysql-4.1.16
         2.
            %>./configure â??without-server
   5.
      Make and Install mysql (this will NOT effect the Windows Mysql
Server install)
         1.
            %>make
         2.
            %>make install
   6.
      The important files for the mysqlclient are:
         1.
            /usr/local/lib/mysql/libmysqlclient.a
         2.
            /usr/local/include/mysql/mysql.h
            These files may be in different locations depending on your
install. The other common location of these files will be
/usr/lib/mysql and /usr/include/mysql. This will come into
play when compiling your mysqlclient program.
   7.
      Test file to ensure it all works:
         1.
            Test file:

#include â??mysql.hâ??
int main(){
MYSQL conn;
}

               2.
                  Compile with following options
               3.
                  -I/usr/local/include/mysql
               4.
                  -L/usr/local/lib/mysql-lmysqlclient

            ex. gcc test.c -o test -I/usr/local/include/mysql
-L/usr/local/lib/mysql -lmysqlclient
            The location of these directories may be different for your
install as mentioned above.
   3.
      Problems:
         1.
            I ran into a problem while compiling my test program with
my_compress.o missing from the libmysqlclient.a library
            /usr/local/lib/mysql/libmysqlclient.a(my_compress.o):my_compress.c:(.text+0x5e):
undefined reference to â??_compressâ??
            Solution: to all the .o file into the gcc compile line. The
file is in the libmysql directory in the mysql source
directory.
                  gcc test.c -o test
/cygdrive/c/mysql-src/mysql-4.1.16/libmysql/my_compress.o


References:
www.cygwin.com
www.mysql.org

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]