Perl/MinGW

From Devpit
Jump to: navigation, search

Using MinGW with Perl

The ExtUtils-FakeConfig module available from CPAN allows the compilation of Perl modules and programs with C components using the MinGW port of gcc. However, there are several points about this process that have not been documented in one place yet. This page is an attempt to collect the useful information in one place. This process is for things packaged with a Makefile.PL script to generate a Makefile for the system, not for packages which use a configure script or other mechanism.

This information was gathered using ActivePerl 817 on Windows XP, with ExtUtils-FakeConfig 0.08 and MinGW 3.4.2. It is possible that other versions may have unique issues. Feel free to document any differences encountered on this page.

Tools

The following tools need to be installed to begin compiling:

  • ActiveState ActivePerl
  • MinGW, including at least the following components
    • MSys (The Minimal System), which includes a small POSIX compatibility layer for Windows.
    • gcc-core, which includes the gcc compiler. This is necessary to compile the *.xs wrappers used by Perl modules
    • binutils
    • mingw-runtime
    • w32api
    • Any additional compilers used by the module in question
  • The ExtUtils-FakeConfig Perl module. It can be installed using ActiveState's ppm utility, but you will also need a copy of the source because we will be using a script packaged within.
  • dmake, a make replacement designed for cross-platform use.

The Process using ExtUtils-FakeConfig 0.08

Once the software is installed, the next step is to create the import library required by MinGW to link against. "cd" into the directory containing the source for the ExtUtils-FakeConfig module, and run one of the following commands:

  • For ActivePerl 6xx builds corresponding to Perl 5.6: perl script/make_implib.pl --output-dir=<perl installation directory>/lib/CORE --output-lib=libperl56.a --target=mingw <perl installation directory>/bin/perl56.dll
  • For ActivePerl 8xx builds corresponding to Perl 5.8: perl script/make_implib.pl --output-dir=<perl installation directory>/lib/CORE --output-lib=libperl56.a --target=mingw <perl installation directory>/bin/perl58.dll

In both cases, this will create a library called libperl56.a, even for the 8xx builds of ActivePerl. This is desirable because the ExtUtils-FakeConfig module outputs a Makefile that references libperl56.a explicitly. This may be a bug, and so it may be more ideal to create the file as libperl58.a and create a MinGW link to it for libperl56.a. This can also be fixed by going in and replacing 8 with 6.

Once you have your import library, cd into the directory of the module which you wish to build. run the command perl -MConfig_m Makefile.PL to build the Makefile. Once that completes, if successful, the library should be ready to build by running dmake, dmake test, and dmake install.

Misc

Note: A major reason for wanting to use MINGW with Perl is to compile a package. However, if you are using Active Perl, you may not need to compile your own modules. ActivePerl maintains a current build of most CPAN packages. Simply use their PPM utility. (e.g. type "ppm" at the cmd prompt and once at the ppm prompt type "install package-name"). However, for the packages that are NOT available through the ActivePerl repoitory for Win32 and for the packages that do not have direct Win32 support, this is a great way to compile and install the packages.