mlpack  master
Building mlpack

Introduction

This document discusses how to build mlpack from source. However, mlpack is in the repositories of many Linux distributions and so it may be easier to use the package manager for your system. For example, on Ubuntu, you can install mlpack with the following command:

$ sudo apt-get install libmlpack-dev

If mlpack is not available in your system's package manager, then you can follow this document for how to compile and install mlpack from source.

mlpack uses CMake as a build system and allows several flexible build configuration options. One can consult any of numerous CMake tutorials for further documentation, but this tutorial should be enough to get mlpack built and installed on most Linux and UNIX-like systems (including OS X). If you want to build mlpack on Windows, see Keon's excellent tutorial.

latest mlpack build

Download latest mlpack build from here: mlpack-2.1.1

Creating Build Directory

Once the mlpack source is unpacked, you should create a build directory.

$ cd mlpack-2.1.1
$ mkdir build

The directory can have any name, not just 'build', but 'build' is sufficient enough.

Dependencies of mlpack

mlpack depends on the following libraries, which need to be installed on the system and have headers present:

In Ubuntu and Debian, you can get all of these dependencies through apt:

# apt-get install libboost-math-dev libboost-program-options-dev
libboost-test-dev libboost-serialization-dev libarmadillo-dev binutils-dev

On Fedora, Red Hat, or CentOS, these same dependencies can be obtained via dnf:

# dnf install boost-devel boost-test boost-program-options boost-math
armadillo-devel binutils-devel

Configuring CMake

Running CMake is the equivalent to running ./configure with autotools. If you are working with the svn trunk version of mlpack and run CMake with no options, it will configure the project to build with debugging symbols and profiling information: If you are working with a release of mlpack, running CMake with no options will configure the project to build without debugging or profiling information (for speed).

$ cd build
$ cmake ../

You can manually specify options to compile with or without debugging information and profiling information (i.e. as fast as possible):

$ cd build
$ cmake -D DEBUG=OFF -D PROFILE=OFF ../

The full list of options mlpack allows:

Each option can be specified to CMake with the '-D' flag. Other tools can also be used to configure CMake, but those are not documented here.

Building mlpack

Once CMake is configured, building the library is as simple as typing 'make'. This will build all library components as well as 'mlpack_test'.

$ make
Scanning dependencies of target mlpack
[ 1%] Building CXX object
src/mlpack/CMakeFiles/mlpack.dir/core/optimizers/aug_lagrangian/aug_lagrangian_test_functions.cpp.o
<...>

You can specify individual components which you want to build, if you do not want to build everything in the library:

$ make mlpack_pca mlpack_knn mlpack_kfn

One particular component of interest is mlpack_test, which runs the mlpack test suite. You can build this component with

$ make mlpack_test

and then run all of the tests, or an individual test suite:

$ bin/mlpack_test
$ bin/mlpack_test -t KNNTest

If the build fails and you cannot figure out why, register an account on Github and submit an issue and the mlpack developers will quickly help you figure it out:

http://mlpack.org/ http://github.com/mlpack/mlpack

Alternately, mlpack help can be found in IRC at #mlpack on irc.freenode.net.

Installing mlpack

If you wish to install mlpack to /usr/include/mlpack/ and /usr/lib/ and /usr/bin/, once it has built, make sure you have root privileges (or write permissions to those two directories), and simply type

# make install

You can now run the executables by name; you can link against mlpack with -lmlpack, and the mlpack headers are found in /usr/include/mlpack/.