Compiling DBD::mysql and DBD::Oracle on windows
Last week my laptop crashed and while installing the new one I decided to update my perl versions. I mainly use the DBD::mysql and DBD::Oracle modules and although I'm confortable building them on Linux/Unix, like most people I use the Activestate binaries on windows.
However it turns out that Oracle licensing changes now prevent Activestate from distributing an Oracle binary, so I was forced to build them from source. It wasn't easy, but now both the Oracle and MySQL modules are working. Here's the procedure in case it helps anyone.
Install Pxperl
Firstly, you probably want to move to the pxperl windows binaries. Pxperl support the familiar CPAN system for updates. Get Pxperl at www.pxperl.com. The installation should be straight forward.
I installed into c:\tools\pxperl
Install MinGW
You'll need a C compiler capable of building native windows binaries. I used the MinGW system. You can't use cygwin, although I believe that Cygwin might be capable of installing MinGW. Anyway, I got the MinGW system from http://www.mingw.org/. I couldn't use the auto-installer for firewall reasons, so I did a manual download and install.
Firstly, I unpacked the following .gz files into c:\tools\mingw:
gcc-java-3.4.2-20040916-1.tar.gz
gcc-objc-3.4.2-20040916-1.tar.gz
mingw-runtime-3.9.tar.gz w32api-3.5.tar.gz
binutils-2.15.91-20040904-1.tar.gz
mingw-utils-0.3.tar.gz gcc-core-3.4.2-20040916-1.tar.gz
gcc-g++-3.4.2-20040916-1.tar.gz
You probably don't need all of these, and of course the version numbers might be different by the time you read this.
Then I ran the following two executables
MSYS-1.0.10.exe
msysDTK-1.0.1.exe
...installing both into c:\tools\msys. You must make sure you provide the correct location for MinGW when prompted. Finally, MinGW installs it's own version of perl, so I removed that as well as the make.exe which is inferior.
I added both the bin directories to my path, which now starts something like this: c:\mysql;c:\tools\msys\1.0\bin; c:\tools\mingw\bin; C:\tools\PXPerl\parrot\bin; C:\tools\PXPerl\bin
Installing DBD::Oracle
Now you can go into cpan (just type CPAN at the command line) and run "Install DBI". That worked OK for me.
Then I ran "install DBD::Oracle". That failed. I can't remember the exact error, but it turns out that a trailing backslash in the include directory for the DBI doesn't work on Windows. To fix that, run "configure_pxperl" and add an include for that directory in the "Include Directories" section. For me, the directory was /tools/PXPerl/site/lib/auto/DBI
, since I installed pxperl into the tools directory.
Installing DBD::Mysql
For some reason I thought this would be the easy part. But it actually was really difficult.
In the end, it turns out you need to create your own version of mysqlclient.lib and manually link to that. Check out MySQL Bugs: #8906, for some more details. Here's the steps that worked for me:
- run "install DBD::mysql" from the CPAN prompt
- You will get a whole lot of undefined symbol errors which will include the names of the normal mysql client API calls, suffixed with '@4' , '@0' , etc. Make a list of all of these.
- Add the missing symbols to the file include/libmysql.def.
- Build your own libmysqlclient library with the following commands (from the directory just above your include directory):
dlltool --input-def include/libmySQL.def --dllname lib/libmySQL.dll --output-lib lib/libmysqlclient2.a -k
-
Go to the CPAN build area for the DBD-mysql, for me that was:
cd \tools\PXPerl\.cpan\build\DBD-mysql-3.0002
-
nmake realclean
-
perl Makefile.PL --libs="-L/mysql/lib -lmysqlclient2 -lz -lm -lcrypt -lnsl"
-
nmake install
And - voila! - you should be OK. The only think you might need to do now is add the top level MySQL directory to your path. DBD-Mysql wants to find "lib/mysql.dll" so you need to add the directory above that to your path. I moved all the libraries to c:\mysql\lib and include files to c:\mysql\include, so I added to my path like this:
set PATH=c:\mysql;%PATH%
All done!
Seems to be working OK now for both Oracle and MySQL. Much more difficult than installing the Activestate binaries but at least now that I'm working from source I can potentially fix bugs although having done it on Linux it's not for the faint hearted (or the incompentent in C++!)
Hopefully pxperl will gain in popularity and as it matures things will work as easily as on Linux. That would be great.
Reader Comments (4)