Aww Sheezy!

DBD::mysql, DBI, Perl, MySQL, and Cygwin – Together at last

by on May.03, 2011, under Hacking, How-To, Software, Tech

Hey Guys,

I wanted to bring back to life a perl script that I had written some time back that made heavy use of DBD::mysql. I already had Cygwin installed (Windows 7 64bit on this laptop), and Perl is available for Cygwin, so this should be cake, right?

Well, not really.

So, I go to run my script, knowing it will likely fail seeing as I had yet to attempt any database related scripting on this particular laptop, and Perl needs things to be setup.

I was right. It failed. Complaining about lacking Sooo.. that’s easy, let’s fix that:
cpan DBI

Done. Let’s run the script again and see what our next failure is. This time it’s complaining about the lack of “DBD::mysql”. Well, that’s easy, let’s fix that:
cpan DBD::mysql

Ooh it didn’t like that. It’s complaining about not being able to find “mysql_config”, and it seems to be looking for some C headers as well. A quick search throug Google points out that I will need to install the MySQL client, from source, in order for DBD::mysql to be compiled properly.

So I go about downloading the latest version of MySQL from source, which at the time of me writing this is “5.5.11”. I chose the Linux version, architecture independent.

I come to find out that in MySQL 5.5.11, they have abandoned “configure”, for what seems like a slicker way to do the same thing via something called “cmake”. I’ve never used “cmake” before, so I had to kind of fumble through that a bit. After a bit of reading through some documentation, I find that all you do with “cmake” is to make a directory where you want program built, and run “cmake (source dir)”, i.e.
$ mkdir bld
$ cd bld
$ cmake ..

Right away I ran into a ton of library dependencies my system was lacking. Cygwin is great in that all I had to do was run the Setup program a number of times for each piece of software I needed and it would take care of all the interdependencies for me. Here’s a list of what I ended up getting installed in order to meet the prereqs for the build:


I then look up what people seem to be using for their cmake string and I end up with this:

I then run “make” and end up at the following error related to “strings/dtoa.c”:
[ 5%] Building C object strings/CMakeFiles/strings.dir/dtoa.c.o
/home/Mike/mysql-5.5.11/strings/dtoa.c:55: error: conflicting types for ‘dtoa’
/usr/include/stdlib.h:162: error: previous declaration of ‘dtoa’ was here
make[2]: *** [strings/CMakeFiles/strings.dir/dtoa.c.o] Error 1
make[1]: *** [strings/CMakeFiles/strings.dir/all] Error 2
make: *** [all] Error 2

The fix for that is to modify “strings/dtoa.c” and rename any dtoa() call to a _dtoa() call, since the dtoa() calls within “strings/dtoa.c” are conflicting with some dtoa() calls within “/usr/include/stdlib.h”.

I rerun “make” and get 86% into the build before I come up on another error building “”.:
[ 86%] Building CXX object sql/CMakeFiles/mysqld.dir/
Linking CXX executable mysqld.exe
Creating library file: libmysqld.dll.a
libsql.a($_ZTV12Comp_creator[vtable for Comp_creator]+0x10): undefined reference to `___cxa_pure_virtual'
libsql.a($_ZTV12Comp_creator[vtable for Comp_creator]+0x14): undefined reference to `___cxa_pure_virtual'
libsql.a($_ZTV12Comp_creator[vtable for Comp_creator]+0x18): undefined reference to `___cxa_pure_virtual'
libsql.a($_ZTV12Comp_creator[vtable for Comp_creator]+0x1c): undefined reference to `___cxa_pure_virtual'
libsql.a($_ZTV16Unknown_key_hook[vtable for Unknown_key_hook]+0x10): undefined reference to `___cxa_pure_virtual'
libsql.a($_ZTV19Item_basic_constant[vtable for Item_basic_constant]+0x40): more undefined references to `___cxa_pure_virtual' follow
collect2: ld returned 1 exit status
make[2]: *** [sql/mysqld.exe] Error 1
make[1]: *** [sql/CMakeFiles/mysqld.dir/all] Error 2
make: *** [all] Error 2

All the Google in the world led me to a bunch of other frustrated developers that were unable to get Cygwin and MySQL to live together.

I thought it would be good to maybe try and older version, one that still used “configure”, instead of “cmake”, not that there was anything wrong with “cmake”, it’s just that I had kind of reached the end of how much I wanted to continue troubleshooting this release.

So I downloaded the source to MySQL 5.1.56, which is the latest from the 5.1 release at the time of me writing this.
$ ./configure --without-server
$ ./make

Damnit, another error, this time related to “readline”.
$ make clean
$ ./configure --without-server --without-readline
$ make

Damnit, another error, looks like this: error: redefinition of ‘struct _hist_entry’
../include/readline/readline.h:46: error: previous definition of ‘struct _hist_entry’ error: invalid type in declaration before ‘;’ token error: conflicting declaration ‘typedef int HIST_ENTRY’
../include/readline/readline.h:49: error: ‘HIST_ENTRY’ has a previous declaration as ‘typedef struct _hist_entry HIST_ENTRY’ In function ‘void initialize_readline(char*)’: error: ‘rl_completion_func_t’ was not declared in this scope error: expected primary-expression before ‘)’ token error: invalid conversion from ‘char* (*)(const char*, int)’ to ‘int (*)(const char*, int)’ error: ‘rl_command_func_t’ was not declared in this scope error: expected primary-expression before ‘)’ token
make[2]: *** [mysql.o] Error 1
make[2]: Leaving directory `/home/Mike/mysql-5.1.56/client'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/Mike/mysql-5.1.56/client'
make: *** [all-recursive] Error 1

Ugh.. ok let me Google the crap out of this. I ended up lucking out and finding someone with the exact same problem that seemed to have been able to move forward.
$ make clean
$ ./configure --without-server --without-readline CFLAGS=-O2 CXXFLAGS=-02
$ make

Success! No errors!
$ make install

Success! No errors!

Now let’s try out this DBD::mysql install once more
$ cpan DBD::mysql

Success! No errors! And to top it all off, my Perl script works now.

:, , , , , , , ,