Building libexpat and XML::Parser on Windows 8.1 64 bit using Visual Studio 2013

One of the two main stumbling blocks I have had to a really fulfilling experience with my self-built perls on Windows has been my failure to build libexpat, and libgd.

I am going to talk about libgd later, when I have had a chance to try version 2.1.1, but, it seems part of the problem I was having with libexpat was my insistence on using command line tools only. It's an old habit, hard to break, but I am much more comfortable in the shell rather than an IDE, but after my most recent attempt, and subsequent failure once again to produce something that worked with XML::Parser, I decided to drop into the Visual Studio 2013 IDE.

Prior to this, the closest I had come to success was using CMake. Unfortunately, while the bundled executables worked properly, XML::Parser's Expat.dll failed to load properly giving various "ordinal not found" style errors.

libexpat comes with a expat-2.1.0/expat.dsw file which is the project file format for older versions of Visual Studio. Opening that in Visual Studio 2013 IDE prompts for a conversion:

After the import concludes, you get a solution called expat with seven projects:

Initially, the project settings are for a Win32 Debug build:

which you need to change to x64 Release:

In addition, I added the WIN64 define in the expat project's properties, and changed the optimization settings:

I didn't actually compare if optimizing for size made a difference, but that is my default right now.

I also neglected to fix hard-coded output directories which means the output will be in expat-2.1.0\win32\bin\Release

Then, a CTRL-SHIFT-B built the project.

Then, to see if everything actually worked properly, I downloaded XML::Parser, and added expat-2.1.0\lib to my INCLUDE and LIB directories (when this worked, I moved those files to the places where I usually put such things ;-):

I then moved expat.h and expat_external.h to c:\opt\include, the DLLs and EXEs to c:\opt\bin, and the LIBs and the EXPs to c:\opt\lib, and added those to the default search paths:

C:\…\XML-Parser-2.44> set lib=%lib%;C:\opt\lib
C:\…\XML-Parser-2.44> set include=%include%;c:\opt\include

Now, even with those, perl Makefile.PL told me it could not find libexpat, but, I went ahead and did an nmake test et voilà:

t\astress.t ........... ok
t\cdata.t ............. ok
t\decl.t .............. ok
t\defaulted.t ......... ok
t\encoding.t .......... ok
t\external_ent.t ...... ok
t\file.t .............. ok
t\file_open_scalar.t .. ok
t\finish.t ............ ok
t\namespaces.t ........ ok
t\parament.t .......... ok
t\partial.t ........... ok
t\skip.t .............. ok
t\stream.t ............ ok
t\styles.t ............ ok
All tests successful.
Files=15, Tests=141,  4 wallclock secs ( 0.17 usr +  0.08 sys =  0.25 CPU)
Result: PASS

Which means XML::Twig built without a hitch.