bramz' diary : Building OpenEXR libraries for Windows x64
May 25th, 2010 by bramzLiAR supports the OpenEXR file format for several months now, but I only had it working on 32-bit windows. I was still missing the binaries for the 64-bit build, as you need to build the library yourself. For 64-bit Windows that turns out to be one tricky affair:
- Only Visual Studio solution files are available so that rules out nmake.
- DLL creation involves an custom build tailored for x86.
- The Visual C++ Express editions are x86 only anyway, so you have to work around that as well.
- And surprisingly, it seems that no-one has ever bothered so before because there’s hardly anything to be found on the web.
After several hours of hairpulling, I’ve finally managed to set up a working x64 build. To document it for future reference, and for other people on the same adventure, here are the magic build steps:
Setting up the build tree
The OpenEXR build is rather picky on the build tree layout. While the absolute location is free for choice, you need to add an extra layer for things to play out nicely. On my machine, I’ve put everything in C:\libs-x64\openexr-1.6.1, but that could be just any other location.
- Download ilmbase-1.0.1.tar.gz and openexr-1.6.1.tar.gz.
- Create
C:\libs-x64\openexr-1.6.1\openexr.This extra layer is necessary to make sure the goodies are gathered in
C:\libs-x64\openexr-1.6.1\Deploy. Otherwise, they would end up inC:\libs-x64\Deploy. - Extract
ilmbase-1.0.1.tar.gzto
C:\libs-x64\openexr-1.6.1\openexr\ilmbase-1.0.1 - Extract
openexr-1.6.1.tar.gzto
C:\libs-x64\openexr-1.6.1\openexr\openexr-1.6.1
Using VC Express for x64 builds
For Windows, OpenEXR comes with Visual Studio project files only. So you must use Visual C++ for building. If you’re using the VC Express edition, that’s a problem because it only has a x86 compiler on board. And you can’t directly use the x64 compiler of the Windows SDK, as that requires nmake makefiles, which you don’t have. But you can do it indirectly …
- Open a Windows SDK CMD shell. This sets all the required environment variables to use the x64 compiler.
"%VCINSTALLDIR%\..\Common7\IDE\VCExpress" /useenvor whatever the location to vcexpress.exe is.The
/useenvswitch is important to tell the IDE not to use the default compiler, but to assume the environment is already setup ready to go. This is exactly why we run this within the Windows SDK shell.- Open a solution and make sure you target the x64 platform.
You won’t be able to setup a new x64 configuration, but you can just open the Win32 configuration, go to the advanced linker options and specify
MachineX64 (/MACHINEX64)as target machine. - Build …
Building IlmBase
IlmBase contains the createDLL project that builds a tool for the custom build steps. You need to tweak its sources to correctly skip names starting with an underscore. Because createDLL assumes the x86 __cdecl calling convention which decorates names with an extra underscore, it actually only skips names that start with at least two underscores. But the x64 calling convention does not decorate them as such, so names starting with a single underscore slip through the net.
- Start VC Express, open
ilmbase-1.0.1\vc\vc8\IlmBase\IlmBase.slnand convert if necessary. - Set the target machine to
MachineX64(see above) - Open
createDLL.cppto make the following code changes:- Replace
/MACHINE:X86by/MACHINE:X64(line 683) - Replace the following (three occurrences!)
// symbol starts with two underbars, skip it
else if (buf[0] == ‘_’ && buf[1] == ‘_’) {by
// symbol starts with underbar, skip it
else if (buf[0] == ‘_’) {
- Replace
- Build …
If you get errors like
fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64', you should have started VCExpress with the /useenv switch from the Windows SDK CMD shell, as described above.
Building zlib:
OpenEXR has a dependency on zlib. So if you don’t have done so yet, now is the time to build it …
- Download zlib125.zip and extract to
C:\libs-x64\zlib-1.2.5 - Open a Windows SDK CMD shell
cd /D C:\libs-x64\zlib-1.2.5set Include=C:\libs-x64\zlib-1.2.5;%Include%nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF" OBJA="inffasx64.obj gvmat64.obj inffas8664.obj"
Building OpenEXR
OpenEXR expects the zlib headers and libraries to be in the Deploy directory as well, so that’s where we’re going to put them.
- Copy
zlib.handzconf.hfromC:\libs-x64\zlib-1.2.5toDeploy\include - Copy
zdll.libto bothDeploy\lib\DebugandDeploy\lib\Release - Copy
zlib1.dllto bothDeploy\bin\DebugandDeploy\bin\Release - Start VCExpress and open
openexr-1.6.1\vc\vc8\OpenEXR\OpenEXR.sln - Set the target machine to
MachineX64(see above) - Build …
That’s it. By now you should have a Deploy directory filled with OpenEXR headers and libraries, ready to be used in your x64 build of, for example, LiAR =)
Happy Towel Day!


