Building FreeImage with Visual Studio 2013, including 64-bit

The FreeImage library is an indispensable tool to create graphics files. Building it with Visual Studio 2013 requires some adjustments to the solution and project files that I describe in this article. Furthermore, I provide a compiled a 64-bit .DLL of FreeImage 3.16.0.

Sam Beauvois has a much-cited blog post on compiling FreeImage 3.13 for 64-bit systems. However, his instructions do not apply for more recent versions of FreeImage such as the current 3.16.0, where different problems have to be solved.

Fixing the build in Visual Studio 2013

The FreeImage library will not build out of the box with Visual Studio 2013 Professional. When the solution file FreeImage.2008.sln is opened in this edition of Visual Studio, a one-way upgrade process will be performed automatically. A subsequent build process will fail with lots of complaints about min and max not being members of the std namespace.

Build errors that occur when trying to build FreeImage out of the box in Visual Studio 2013
Build errors that occur when trying to build FreeImage out of the box in Visual Studio 2013

This is because those function declarations have been moved to a different header file algorithm, and including this header file in the offending FreeImage files will make the errors disappear. Specifically, you will need to add

#include <algorithm>

to the following files:

  • Source/OpenEXR/IlmImf/ImfOutputFile.cpp
  • Source/OpenEXR/IlmImf/ImfScanLineInputFile.cpp
  • Source/OpenEXR/IlmImf/ImfTiledMisc.cpp
  • Source/OpenEXR/IlmImf/ImfTiledOutputFile.cpp
  • Source/OpenEXR/Imath/ImathMatrixAlgo.cpp

The easiest way to open these files is to click on one of the error messages (shown above) and paste the line in the include section.

This is all that is needed to get FreeImage to build in Visual Studio 2013. However, the upgrade process messes up the binary output paths, so you would end up with lots of new directories containing intermediate and final output files all over the place.

Addendum (30-Jan-15): I found out that the default x64 configuration of the FreeImage project enables OpenMP support, which will lead to an external dependency of the FreeImage DLL on vcomp120.dll which may not be present on systems where you deploy the FreeImage DLL. There is a discussion thread that describes how to disable OpenMP in the VisualStudio project. Contrary to what is proposed in the discussion, it only has to be disabled in the FreeImage and LibRaw projects in order to build a FreeImage DLL without depencency on vcomp120.dll. The DLL that can be downloaded below has OpenMP support disabled.

Cleaning up the binary directories

I decided to put all final output binaries in a bin/ directory in the solution’s root directory, and intermediate binaries in a build/ directory, with subdirectories for the current configuration (Debug or Release), the current project, and the current platform (Win32 or x64).

This was done with lots of commands in the Linux terminal like this:

$ find -name '*.vcxproj' -exec sed -i 's_(complicated_regexp)_' {} \;

There were plenty of different locations where paths had to be changed; I consistently used Visual Studio macros for build commands and properties to prevent future problems.

If you are in a similar situation, you may want to use the ZIP file that I provide below; it contains just the .vcxproj files with the corrected paths.

Addendum (30-Jan-15): OpenMP support (see other addendum above) has not been disabled in the projects included in this archive.

To use it, you need to upgrade the FreeImage solution to VS 2013 first, in order to create .vcxproj files. You will also want to use your favorite version control system to make sure your source tree is not messed up accidentally. The commands shown below are on Linux (I have Windows running in virtual machines only), but on Windows, the workflow should be similar.

Fixing build paths in the upgraded solution using the provided ZIP file.
Fixing build paths in the upgraded solution using the provided ZIP file.

64-bit DLL

The FreeImage website offers a download of a 32-bit DLL for Windows, but no 64-bit version. The only 64-bit DLL that I am aware of is Sam Beauvois’ version 3.13. Since FreeImage has been updated to version 3.16.0 in the meantime, I thought I’d provide a 64-bit 3.16.0 DLL for the community, in case someone needs the 64-bit binary, but does not have Visual Studio on a 64-bit Windows.

This DLL is made available under the terms of the GNU General Public License v.3.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.