Building XS Modules for 64bit ActivePerl on Windows

Here I'll discuss how to build extensions for 64bit ActivePerl for Windows using freely available tools.

First let's discuss which perl for Windows you need if you haven't decided that yet.

For most general use and development you want a 32bit ActivePerl or Strawberry Perl. ActivePerl has the advantage of some difficult to build modules available as easy to install PPM packages in the ActiveState repositories or some of the third-party repositories. In other ways the two are similar, ActivePerl will now automatically install the MinGW toolchain and dmake when you need it to compile an extension, the tools Strawberry Perl comes with, or you can just type ppm install MinGW.

The reason you would generally prefer a 32bit perl on Windows is that many modules, especially some Win32:: modules are not compatible with 64bit perls yet; and in the case of ActivePerl, there are far more PPMs available for the 32bit builds.

Your choice of whether to use a 32bit or 64bit perl may be dictated by factors other than convenience and compatibility however, you may need to link the interpreter into a native process of a certain bitness, or link a .dll library of a certain bitness into the perl interpreter. Or you may need to use either a 32bit or 64bit ODBC driver which will only work with that respective bitness of perl. And so on.

Once you've decided that you need to use a 64bit perl, you have a choice between Strawberry Perl and ActivePerl. Strawberry Perl comes with MinGW-w64 and dmake bundled in the distribution and pre-setup for you, so you can skip the setup I describe here for ActivePerl. If you choose to use ActivePerl, for the availability of (some) PPMs or other reasons, read on.

For 64bit ActivePerl you have the choice of two freely available tools to build extensions, the Windows SDK and the MinGW-w64 suite, setup for both is described below.

The Windows SDK

The freely available Windows SDK (current version) contains everything you need including a set of compilers. If however you are getting the Windows 8 SDK you will also need to get Visual Studio Express 11 for the compilers, as the Windows 8 SDK no longer includes a set of compilers.

Now you need to modify your environment to make the SDK tools available to perl (CPAN installations, etc..) I recommend using Rapid Environment Editor, or you can make .cmd file and modify your cmd.exe shortcut to add the /K option and the path to your .cmd file with your settings. I attempted, with some measure of success, to make a system of switching between different perls in a single cmd.exe session in this article.

The settings you need for the Windows 7 SDK are as follows (modify to taste:)

set PATH=C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\x64;C:\Windows\system32;C:\Windows
set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v7.1\Include;C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\gl
set LIB=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Lib\amd64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\X64
set LIBPATH=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Lib\amd64

Now launch cpan in cmd.exe and try to install an XS module such as Class::XSAccessor to test everything out.

If you get link errors about not being able to find bufferoverflowU.lib, edit C:\Perl64\lib\ and remove all instances of bufferoverflowU.lib. This shouldn't happen with the newer ActivePerl builds however.

The settings for the Windows 8 SDK with the Visual Studio Express 11 compilers should be similar, but I have not tried that yet, so don't know the details.


The ActivePerl MinGW mode mostly works with MinGW-w64, although it is meant for the 32bit builds with older suites so some tweaks are necessary.

First download the WIN64 native compiler suite from the MinGW-w64 download page in the WIN64 Downloads -> Personal Builds -> rubenvb -> release section. The file will be named something like x86_64-w64-mingw32-gcc-4.7.0-release-win64_rubenvb.7z. Unpack with 7-zip or WinRAR everything below the top level directory in the archive to C:\MinGW_w64 .

Modify your PATH to add C:\MinGW_w64\bin . See the part about environment settings in the previous section, I recommend Rapid Environment Editor.

Set the LIBRARY_PATH environment variable as follows:

set LIBRARY_PATH=C:\MinGW_w64\x86_64-w64-mingw32\lib

Now install dmake. We'll use a 32bit binary from CPAN so make sure that WOW64 is enabled in your OS if you are using an older server OS. Download the dmake dist from CPAN, open the archive, go into the dmake folder, and extract dmake.exe and the startup subfolder into C:\Perl64\site\bin . Then run:

icacls c:\perl64\site\bin\dmake.exe /grant your_user_name:(rx)

Next edit C:\Perl64\lib\ and remove all instances of bufferoverflowU.lib.

That's all there is to it. Now with gcc.exe in your PATH ActivePerl will go into mingw mode when it needs to build an extension, try it now by running cpan Class::XSAccessor or some such extension.

Note that if you will package Perl applications with built extensions, you will need to include the libgcc and libstdc++ (if there were any C++ extensions) DLLs with your package, to be run from the same directory as the perl interpreter or somewhere in PATH. This is also true for the new versions of the 32bit toolchain. The alternative is to include

-static-libgcc -static-libstdc++

in your LDDLFLAGS along with the default $Config{lddlflags}. I'm going to submit a bug report to ActiveState to make these options default for newer gccs.

Last modified: 2017-1-8 (日) at 9:14 pm