How to install mlpack on windows

I usually use Vim on Ubuntu for any type of development.
Lately I tried installing mlpack on Windows 10 to try programming on Visual Studio 2015, which I heard is very good for debugging.

I used appveyor instructions to build mlpack. I think this is the simplest way of building mlpack since most of the dependencies (except for armadillo) used is pre-compiled.

If you want to compile every dependencies from source, please refer to this blog

Prerequisites

The following tools are needed:

Step 1, Download mlpack.

First, create a project folder. For this example, I used C:/projects/ folder. And download the latest stable version of mlpack and place it under projects folder. So the folder structure now becomes C:/projects/mlpack-2.0.1/.

Warning: I got unsuccessful with 2.0.1 release. Instead, download from the master branch on github.

Step 2. Setup mlpack in Visual Studio and download some dependencies using NuGet.

step2-1

open Visual Studio and click File > New > Project from Existing Code.

step2-2
step2-3

Select Visual C++ (not that important) and select the file location (in this case, C:/projects/mlpack-2.0.1/). Give any project name (can be anything, but I used mlpack for this example) and click Finish.

Next, it is time to download the dependencies using NuGet. NuGet is something like apt-get for debian. It makes things a lot easier and less time consuming.

step2-4

Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution and click Browse tab.

step2-5

I want to download OpenBLAS so search for it and click the project (mlpack) which you want to apply.

step2-9

You can search for the names of the dependencies to download. If somehow you don’t see NuGet Package Manager on your menu, you need to install NuGet for Visual Studio.

Do the same for the following dependencies.

  • boost
  • boost_unit_test_framework-vc140
  • boost_program_options-vc140
  • boost_random-vc140
  • boost_serialization-vc140
  • boost_math_c99-vc140
  • OpenBLAS

step2-10

When you are done, you should see the packages installed in C:projects/mlpack-2.0.1/packages. To make them easier to work with CMake, you should gather all boost libraries into one folder. To do that, make a new folder named boost_libs under packages folder.

Now copy and paste everything (total of 5) under the following folders to boost_libs

  • boost_math_c99-vc140.1.60.0.0/lib/native/address-model-64/lib
  • boost_program_options-vc140.1.60.0.0/lib/native/address-model-64/lib
  • boost_unit_test_framework-vc140.1.60.0.0/lib/native/address-model-64/lib
  • boost_serialization-vc140.1.60.0.0/lib/native/address-model-64/lib
  • boost_random-vc140.1.60.0.0/lib/native/address-model-64/lib

now boost_libs should look like the following picture.

step2-12

Step 3, Download Armadillo and Build it.

Unfortunately, there is no NuGet package of Armadillo. So we need to build it manually.

Download the latest stable version of Armadillo. As a courtesy, the Armadillo package contains pre-compiled 64bit versions of standard LAPACK and BLAS. You extract it anywhere, but for this example I extracted it under C:/projects/ folder. projects folder now cotains armadillo-7.100.3 and mlpack-2.0.1

Under armadillo-7.100.3, create a new folder named build. And now go to command prompt by pressing windows button and typing cmd. Make sure you can use cmake in the command prompt.
go to the build folder you just made, and copy and paste the following (all in one line).

step3-13

1
cmake -G "Visual Studio 14 2015 Win64" -DBLAS_LIBRARY:FILEPATH="C:/projects/mlpack-2.0.1/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" -DLAPACK_LIBRARY:FILEPATH="C:/projects/mlpack-2.0.1/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" -DCMAKE_PREFIX:FILEPATH="C:/projects/armadillo" -DBUILD_SHARED_LIBS=OFF ..

If you used different directories other than ones used in this example, you must change the input accordingly. I broke the lines so that it is easier for you to edit.

1
2
3
4
5
6
cmake
-G "Visual Studio 14 2015 Win64"
-DBLAS_LIBRARY:FILEPATH="C:/projects/mlpack-2.0.1/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"
-DLAPACK_LIBRARY:FILEPATH="C:/projects/mlpack-2.0.1/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"
-DCMAKE_PREFIX:FILEPATH="C:/projects/armadillo"
-DBUILD_SHARED_LIBS=OFF ..

step3-14

Cmake then should create many files below build folder. click on armadillo.sln file to open with Visual Studio. Next, click “Build > Build Solution” to build armadillo.
When you are done, close Visual Studio and go to step 4.

Step 4, Build mlpack.

Now you can finally build mlpack!

The instructions are same as building armadillo, so it should be easier as you’ve already done it once.

step3-15

Copy and paste the following to the commandline.

1
cmake -G "Visual Studio 14 2015 Win64" -DBLAS_LIBRARY:FILEPATH="C:/projects/mlpack-2.0.1/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" -DLAPACK_LIBRARY:FILEPATH="C:/projects/mlpack-2.0.1/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a" -DARMADILLO_INCLUDE_DIR="C:/projects/armadillo-7.100.3/include" -DARMADILLO_LIBRARY:FILEPATH="C:/projects/armadillo-7.100.3/build/Debug/armadillo.lib" -DBOOST_INCLUDEDIR:PATH="C:/projects/mlpack-2.0.1/packages/boost.1.60.0.0/lib/native/include" -DBOOST_LIBRARYDIR:PATH="C:/projects/mlpack-2.0.1/packages/boost_libs" -DDEBUG=OFF -DPROFILE=OFF ..

Again, if you used different directories along the way, you must edit it accordingly. I broke down the flags for you.

1
2
3
4
5
6
7
8
9
cmake
-G "Visual Studio 14 2015 Win64"
-DBLAS_LIBRARY:FILEPATH="C:/projects/mlpack-2.0.1/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"
-DLAPACK_LIBRARY:FILEPATH="C:/projects/mlpack-2.0.1/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"
-DARMADILLO_INCLUDE_DIR="C:/projects/armadillo-7.100.3/include"
-DARMADILLO_LIBRARY:FILEPATH="C:/projects/armadillo-7.100.3/build/Debug/armadillo.lib"
-DBOOST_INCLUDEDIR:PATH="C:/projects/mlpack-2.0.1/packages/boost.1.60.0.0/lib/native/include"
-DBOOST_LIBRARYDIR:PATH="C:/projects/mlpack-2.0.1/packages/boost_libs"
-DDEBUG=OFF -DPROFILE=OFF ..

step3-16

now open the mlpack.sln file (under the build folder) with Visual Studio.

step3-17

Click Build > Build Solution. It is going to take a while to build. And congratulations!

You just successfully built mlpack.

notice

if while building mlpack in a windows Visual Studio environment and you receive error C1128 go to the the specific project in Solution Explorer highlight it > Next go to ‘Project’ > ‘Properties’ > ‘C/C++’ > ‘Command Line’ and add /bigobj to ‘Additional Options. After that mlpack will build successfully on Visual Studios 15’