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]

Re: MySQL 5.0.21 C API under cygwin

Eric Lilja wrote:
For a long time I've been wanting to compile C/C++ programs that can talk to a MySQL server under Cygwin. I tried to compile to several version of MySQL (configuring with the flag --without-server), but the build process always ended with some error. I also tried to convert the msvc-libraries that come with the Windows version of MySQL to a MingW-usable format. After a lot of hassle I could get my programs to link, but the resulting executables crashed almost right away. Probably some nice stack corruption or some such. Seeing no other option, I ended up using MSVC to compile my programs that talk to the native Windows MySQL database.

But last night I decided to give it another shot. Cygwin had seen alot of improvements since I last tried and MySQL version 5 (the version I'm interested in) had also seen several updates.
Using a fully updated Cygwin, I compiled MySQL 5.0.21 with --disable-server (and some other disables). It compiled cleanly, woot! Then I tried to link a simple test program compiled using cygwin's gcc. It complained about some undefined references, but I solved that by linking to zlib (-lz) *after* linking the mysql libraries.

Then I started the native Windows MySQL server on the same machine and tried to connect. The program ended with the following error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

So I the changed mysql_real_connect() call to connect to "" instead of "localhost" and specified port 3306 instead 0 and then it worked! My simple test program created a table and inserted a tuple and it works!

I just wanted to share this if someone else is wants to do what I want to: Develop C/C++ programs using Cygwin that talk to a native Windows MySQL server.

/ E


I'm chuckling at the synopsis of your process because I went through the exact same series of trials and errors. The issue with the /tmp/mysql.sock is that MySQL uses domain sockets for *NIX machines and named pipes on Windows machines. Specifying the IP address uses TCP/IP sockets, which work as expected.

I was compiling the server for the Perl::DBI module, which required libraries and headers to link against.

* Nicholas

-- Unsubscribe info: Problem reports: Documentation: FAQ:

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