wiki:MLPACKOnWindows

MLPACK On Windows

MLPACK, while not designed with Windows as a specific target, can still be built and run on Windows without too much pain (with some exceptions). This document details the steps necessary to get MLPACK compiled using Microsoft Visual Studio 2010. (Currently, mlpack will _only_ build on Visual Studio 2013 and newer because of C++11 support issues.)

Unfortunately it seems that in some settings, MLPACK will cause the Visual Studio compiler to issue C1001 errors (internal compiler errors; essentially bugs in the compiler): #225. One solution is to use the Intel C++ compiler instead of the Visual Studio compiler.

windows logo

Prerequisites

Before MLPACK can be installed, you'll need to get a few software packages. First, you'll need a working compiler (in this case, I'm using Visual Studio). Then, get the following packages below and install them (or place them) on your system:

  • CMake; the Windows installer (found  here) will work just fine.
  • Boost (you can get this from  BoostPro; I don't recommend trying to compile and install Boost yourself. The components of Boost we use are Program Options, Random, Math (C99), and the Unit Test Framework (or Boost.Test). Be sure to install the versions which are right for your compiler.
  • Armadillo (>= 3.6.0). You can download this from the  Armadillo website. You will probably have to build this yourself; when you configure it with CMake, ensure that it links against LAPACK and BLAS. The Armadillo directory contains a LAPACK and BLAS library in examples/lib_win32/. Armadillo for Windows is not very polished, so in my case I just modified include/armadillo_bits/config.hpp to tell Armadillo I had LAPACK and BLAS, and then later told MLPACK to link against the LAPACK and BLAS libraries given in examples/lib_win32. If you install Armadillo in C:\Program Files\Armadillo\, CMake will have an easy time finding it later on. Be sure that armadillo.lib (not armadillo.dll) is built, because you need to link against armadillo.lib.
  • ZLIB (or just zlib1.dll). You don't actually need anything more than just zlib1.dll on your system somewhere; if you don't have it, you can get it from the  ZLIB download page.
  • iconv (or just iconv.h and iconv.dll). Similar to ZLIB, you need the library, but in this case you also need the header file iconv.h. If you don't have it, you can get it from the  iconv download page.

CMake configuration

Once you have all those prerequisites, open the CMake executable. Give it the location of your MLPACK source and the directory you want to be a build directory (this should be a different directory; for more information on why, do a quick search on 'out-of-source builds' and why they are good).

If you are lucky, when you hit 'Configure', CMake will give no errors and everything will work great. However, this is unlikely. The following variables can be set to help CMake find the location of important files:

  • ARMADILLO_LIBRARY: the location of libarmadillo.lib or armadillo.lib (FILEPATH).
  • ARMADILLO_INCLUDE_DIR: the directory containing the armadillo header file and armadillo_bits directory (PATH).
  • LAPACK_LIBRARY: the location of the LAPACK library (FILEPATH). Remember, Armadillo ships with examples/lib_win32/lapack_win32_MT.lib.
  • BLAS_LIBRARY: the location of the BLAS library (FILEPATH). Remember, Armadillo ships with examples/lib_win32/blas_win32_MT.lib.
  • BOOST_ROOT: root of Boost installation directory. If you specify this, you probably don't need to specify either of the other BOOST_ variables (PATH).
  • BOOST_INCLUDEDIR: where the Boost include files are located (PATH).
  • BOOST_LIBRARYDIR: where the Boost library files are located (PATH).
  • ICONV_HEADER: location of iconv.h (FILEPATH).
  • ICONV_LIBRARY: location of iconv.dll (FILEPATH).
  • LIBXML2_INCLUDE_DIR: location of libxml2 includes (PATH).
  • LIBXML2_LIBRARIES: location of libxml2.lib (FILEPATH) (sometimes it is necessary to link against libxml2_a.lib).
  • ZLIB_LIBRARY: location of zlib1.dll (FILEPATH).

When all these variables are set right, CMake should configure the project successfully. Then, hit 'Generate' to generate the solution files.

Open the generated solution file, and you should be good to go!

Using MLPACK in other applications

If you want to write your own application and link MLPACK against it, you will need to add the include directories of MLPACK to your project and add mlpack.lib to the libraries you link against.

Further Thoughts

Compiling MLPACK on Windows is a tedious affair. Maybe your situation does not permit it, but perhaps you should consider using Linux (or another UNIX-like system, such as Mac OS X or FreeBSD or similar)? In those cases configuring and compiling MLPACK is as simple as:

$ wget http://www.mlpack.org/files/mlpack-1.0.1.tar.gz
$ tar -xzpf mlpack-1.0.1.tar.gz
$ mkdir mlpack/build
$ cd mlpack/build/
$ cmake ../
$ make

Other Documentation

More information might be found in the following Windows-related tickets:

Attachments