1

How can I set up MySQL so that i can have header-files and libraries in my Cygwin gcc C++ builds?

I have seen descriptions on the web, but it seems to refer to stuff I don't have, Like "configure. (I suspect MySQL has changed their build system).

Using an older version could be an option, but I would prefer to have the same versions as on Linux.

I have a full Cygwin install.

Olav
  • 1,758
  • 4
  • 27
  • 49

1 Answers1

2

First, what's wrong with just using the Windows version? It works fine.

Then, I've wanted to do the same thing as you, and it can be done. Note that I haven't attempted to build the server; all I was interested in was the MySQL client library so I could do some simple client development in the Cygwin environment.

So what do you have to do in order to build the client library on Cygwin?

First, get the tarball. I used mysql-5.5.13.tar.gz. Unpack it in a suitable location, like /usr/local/src.

Then, install the CMake build system via the Cygwin installer. MySQL has switched from GNU Autotools to CMake. CMake is a meta-build system. It generates Makefiles and other build scripts for specific build environments.

Of course, you also need make and gcc.

I had to apply an innocuous little patch posted on the MySQL forum by one Hiroaki Kawai in order to get the stuff to compile:

Finally, I renamed all dtoa() to _dtoa() in mysql/strings/dtoa.c. The function is static, and should be safe to be renamed.

You can patch using Perl:

perl -pi.orig -e 's/\bdtoa\b/_dtoa/g' strings/dtoa.c

Then, in the top source directory, type:

cmake .
make mysqlclient

You'll get two static libraries in libmysql/, libclientlib.a and libmysqlclient.a. I don't know that the former is (possibly just a build artefact), but the latter is the real thing.

cp /usr/local/src/mysql-5.5/libmysql/libmysqlclient.a /usr/local/lib/

But it's static, and you likely want a dynamic library. This is where the Cygwin docs come in handy. So:

module=mysqlclient
gcc -shared -o cyg${module}.dll \
-Wl,--out-implib=lib${module}.dll.a \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import \
-Wl,--whole-archive lib${module}.a \
-Wl,--no-whole-archive -lz

That'll create the shared library cygmysqlclient.dll and the import library libmysqlclient.dll.a. Copy both to /usr/local/bin. And that's it.

Here's another question on building the MySQL client library on Cygwin.

Community
  • 1
  • 1
Lumi
  • 14,775
  • 8
  • 59
  • 92