Skip to content

Compiling Zlib with VS Express 2013 (32-bit dll)

Zlib is one of those libraries that are used in pretty much any other software these days. One can of course get precompiled binaries from its website or from elsewhere, but what is fun with that?!

Building it with VS 2013 is quite easy since it comes with a project file for visual studio. Its for version 11, but it openes just fine in VS Express 2013 too. Slight annoyance: Express 2013 openes solution file, but does not upgrade it!? 🙂 Even more annoying: I had to right click on each project and choose to upgrade it to use new tools. I don’t know if there is some batch option or some setting somewhere, but it feels like VS should figure out this on its own. I suppose if there were old and new SDKs installed on this machine it might get cautios or confused, but there are not.

Anyway there is a minor fix needed to be done regarding safe exception handler. Info about exception handler an be found on MSDN. A nice info can be read in Yasm assembler manual as well. One way to fix this is to change linker settings not to use safe exception handler att all (setting is found under advanced options in linker tab). But there is no reason not to be a good Win32 citizen, so we will compile all the code with /safeseh option instead. Since there is some included assembly code, it has to be compiled as well with this option. In contrib/masmx86 folder, add /safeseh switch to assembly flags to both lines in bld_ml32.bat:

  ml /safeseh /coff /Zi /c /Flmatch686.lst match686.asm
  ml /safeseh /coff /Zi /c /Flinffas32.lst inffas32.asm

Another slight annoyance is versioning of definition file. I actually had to google to find what was causing this error. This link explains it. Can’t believe VS team decided to “fix” that error after all this years instead of treating it as a feature and just document it instead :-). Anyway in zlibvc.def change version to something with two numbers (I tried to trick VS and rename version to 1_2_8, but nope it does not work), for me 1.28 is just fine, or simply remove version number, I think it should work as well.

That is pretty much all we have to change to compile Zlib with VS Express 2013.

It is just my taste, but I prefer to add a ‘d’ as trailing end in filename for debug version. Project file has unfortunately hardcoded name for target scattered all over settings so be sure to update all appropriate places if you go this route. I changed target name under general tab, to ‘zwapid’, and then used $(TargetName) macro in linker settings instead of hardcoded name.

Finally I also like to copy final files to a certain directory on my hardrive. I put all 32-bit builds in folder called bin/x86 and all 64-bit builds in bin/x64 which I do in post build event:

    xcopy /y /c $(TargetPath) $(glsdk)bin\x86\
    xcopy /y /c $(TargetDir)$(TargetName).lib $(glsdk)lib\x86\

Glsdk is just an env path I defined on my computer where I collect useful libraries for playing with OpenGL.

As I tried to use zlib in first project I got issue with several symbols missing from the link library. As it seems ZLIB_WINAPI has to be removed from preprocessor definitions, which fixed problem. Solution found in this thread.

Post a Comment

Your email is never published nor shared. Required fields are marked *