\section{Introduction}\label{build_windows_build_windows_intro}
This tutorial will show you how to build mlpack for Windows from source, so you can later create your own C++ applications. Before you try building mlpack, you may want to install mlpack using vcpkg for Windows. If you don\textquotesingle{}t want to install using vcpkg, skip this section and continue with the build tutorial.


\begin{DoxyItemize}
\item Install Git ({\tt https\+://git-\/scm.\+com/downloads} and execute setup)
\item Install C\+Make ({\tt https\+://cmake.\+org/} and execute setup)
\item Install vcpkg ({\tt https\+://github.\+com/\+Microsoft/vcpkg} and execute setup)
\item To install the mlpack library only\+:
\end{DoxyItemize}


\begin{DoxyCode}
PS> .\(\backslash\)vcpkg install mlpack:x64-windows
\end{DoxyCode}



\begin{DoxyItemize}
\item To install mlpack and its console programs\+: 
\begin{DoxyCode}
PS> .\(\backslash\)vcpkg install mlpack[tools]:x64-windows
\end{DoxyCode}

\end{DoxyItemize}

After installing, in Visual Studio, you can create a new project (or open an existing one). The library is immediately ready to be included (via preprocessor directives) and used in your project without additional configuration.\section{Build Environment}\label{build_windows_build_windows_env}
This tutorial has been designed and tested using\+:
\begin{DoxyItemize}
\item Windows 10
\item Visual Studio 2019 (toolset v142)
\item mlpack
\item Open\+B\+L\+A\+S.\+0.\+2.\+14.\+1
\item boost\+\_\+1\+\_\+71\+\_\+0-\/msvc-\/14.\+2-\/64
\item armadillo (newest version)
\item and x64 configuration
\end{DoxyItemize}

The directories and paths used in this tutorial are just for reference purposes.\section{Pre-\/requisites}\label{build_windows_build_windows_prereqs}

\begin{DoxyItemize}
\item Install C\+Make for Windows (win64-\/x64 version from {\tt https\+://cmake.\+org/download/}) and make sure you can use it from the Command Prompt (may need to add the P\+A\+TH to system environment variables or manually set the P\+A\+TH before running C\+Make)
\item Download the latest mlpack release from here\+: {\tt mlpack website}
\end{DoxyItemize}\section{Windows build instructions}\label{build_windows_build_windows_instructions}

\begin{DoxyItemize}
\item Unzip mlpack to \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}mlpack\char`\"{}
\item Open Visual Studio and select\+: File $>$ New $>$ Project from Existing Code
\begin{DoxyItemize}
\item Type of project\+: Visual C++
\item Project location\+: \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}mlpack\char`\"{}
\item Project name\+: mlpack
\item Finish
\end{DoxyItemize}
\item Make sure the solution configuration is \char`\"{}\+Debug\char`\"{} and the solution platform is \char`\"{}x64\char`\"{} for this Visual Studio project
\item We will use this Visual Studio project to get the Open\+B\+L\+AS dependency in the next section
\end{DoxyItemize}\section{Dependencies}\label{build_windows_build_windows_dependencies}
{\bfseries  Open\+B\+L\+AS Dependency }


\begin{DoxyItemize}
\item Open the Nu\+Get packages manager (Tools $>$ Nu\+Get Package Manager $>$ Manage Nu\+Get Packages for Solution...)
\item Click on the “\+Browse” tab and search for “openblas”
\item Click on Open\+Blas and check the mlpack project, then click Install
\item Once it has finished installing, close Visual Studio
\end{DoxyItemize}

{\bfseries  Boost Dependency }

You can either get Boost via Nu\+Get or you can download the prebuilt Windows binaries separately. This tutorial follows the second approach for simplicity.


\begin{DoxyItemize}
\item Download the \char`\"{}\+Prebuilt Windows binaries\char`\"{} of the Boost library (\char`\"{}boost\+\_\+1\+\_\+71\+\_\+0-\/msvc-\/14.\+2-\/64\char`\"{}) from {\tt Sourceforge}
\end{DoxyItemize}

\begin{DoxyNote}{Note}
Make sure you download the M\+S\+VC version that matches your Visual Studio
\end{DoxyNote}

\begin{DoxyItemize}
\item Install or unzip to \char`\"{}\+C\+:\textbackslash{}boost\textbackslash{}\char`\"{}
\end{DoxyItemize}

{\bfseries  Armadillo Dependency }


\begin{DoxyItemize}
\item Download the newest version of Armadillo from {\tt Sourceforge}
\item Unzip to \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}armadillo\char`\"{}
\item Create a \char`\"{}build\char`\"{} directory into \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}armadillo\textbackslash{}\char`\"{}
\item Open the Command Prompt and navigate to \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}armadillo\textbackslash{}build\char`\"{}
\item Run cmake\+:
\end{DoxyItemize}


\begin{DoxyCode}
cmake -G \textcolor{stringliteral}{"Visual Studio 16 2019"} -A x64 -DBLAS\_LIBRARY:FILEPATH=\textcolor{stringliteral}{"
      C:/mlpack/mlpack/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"} -DLAPACK\_LIBRARY:FILEPATH=\textcolor{stringliteral}{"
      C:/mlpack/mlpack/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"} ..
\end{DoxyCode}


\begin{DoxyNote}{Note}
If you are using different directory paths, a different configuration (e.\+g. Release) or a different VS version, update the cmake command accordingly. If C\+Make cannot identify the compiler version, check if the Visual Studio compiler and Windows S\+DK are installed correctly.
\end{DoxyNote}

\begin{DoxyItemize}
\item Once it has successfully finished, open \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}armadillo\textbackslash{}build\textbackslash{}armadillo.\+sln\char`\"{}
\item Build $>$ Build Solution
\item Once it has successfully finished, close Visual Studio
\end{DoxyItemize}\section{Building mlpack}\label{build_windows_build_windows_mlpack}

\begin{DoxyItemize}
\item Create a \char`\"{}build\char`\"{} directory into \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}mlpack\textbackslash{}\char`\"{}
\item You can generate the project using either cmake via command line or G\+UI. If you prefer to use G\+UI, refer to the \doxyref{appendix}{p.}{build_windows_build_windows_appendix}
\item To use the C\+Make command line prompt, open the Command Prompt and navigate to \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}mlpack\textbackslash{}build\char`\"{}
\item Run cmake\+:
\end{DoxyItemize}


\begin{DoxyCode}
cmake -G \textcolor{stringliteral}{"Visual Studio 16 2019"} -A x64 -DBLAS\_LIBRARIES:FILEPATH=\textcolor{stringliteral}{"
      C:/mlpack/mlpack/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"} -DLAPACK\_LIBRARIES:FILEPATH=\textcolor{stringliteral}{"
      C:/mlpack/mlpack/packages/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"} -DARMADILLO\_INCLUDE\_DIR=\textcolor{stringliteral}{"C:/mlpack/armadillo/include"} -
      DARMADILLO\_LIBRARY:FILEPATH=\textcolor{stringliteral}{"C:/mlpack/armadillo/build/Debug/armadillo.lib"} -DBOOST\_INCLUDEDIR:PATH=\textcolor{stringliteral}{"C:/boost/"} -
      DBOOST\_LIBRARYDIR:PATH=\textcolor{stringliteral}{"C:/boost/lib64-msvc-14.2"} -DDEBUG=OFF -DPROFILE=OFF ..
\end{DoxyCode}


\begin{DoxyNote}{Note}
cmake will attempt to automatically download the ensmallen dependency. If for some reason cmake can\textquotesingle{}t download the dependency, you will need to manually download ensmallen from {\tt http\+://ensmallen.\+org/} and extract it to \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}mlpack\textbackslash{}deps\textbackslash{}\char`\"{}. Then, specify the path to ensmallen using the flag\+: -\/\+D\+E\+N\+S\+M\+A\+L\+L\+E\+N\+\_\+\+I\+N\+C\+L\+U\+D\+E\+\_\+\+D\+IR=C\+:/mlpack/mlpack/deps/ensmallen/include
\end{DoxyNote}

\begin{DoxyItemize}
\item Once C\+Make configuration has successfully finished, open \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}mlpack\textbackslash{}build\textbackslash{}mlpack.\+sln\char`\"{}
\item Build $>$ Build Solution (this may be by default in Debug mode)
\item Once it has sucessfully finished, you will find the library files you need in\+: \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}mlpack\textbackslash{}build\textbackslash{}\+Debug\char`\"{} (or \char`\"{}\+C\+:\textbackslash{}mlpack\textbackslash{}mlpack\textbackslash{}build\textbackslash{}\+Release\char`\"{} if you changed to Release mode)
\end{DoxyItemize}

You are ready to create your first application, take a look at the \doxyref{Sample C++ ML App}{p.}{sample_ml_app}\section{Appendix}\label{build_windows_build_windows_appendix}
If you prefer to use cmake G\+UI, follow these instructions\+:


\begin{DoxyItemize}
\item To use the C\+Make G\+UI, open \char`\"{}\+C\+Make\char`\"{}.
\begin{DoxyItemize}
\item For \char`\"{}\+Where is the source code\+:\char`\"{} set {\ttfamily C\+:\textbackslash{}mlpack\textbackslash{}mlpack\textbackslash{}}
\item For \char`\"{}\+Where to build the binaries\+:\char`\"{} set {\ttfamily C\+:\textbackslash{}mlpack\textbackslash{}mlpack\textbackslash{}build}
\item Click {\ttfamily Configure}
\item If there is an error and Armadillo is not found, try \char`\"{}\+Add Entry\char`\"{} with the following variables and reconfigure\+:
\begin{DoxyItemize}
\item Name\+: {\ttfamily A\+R\+M\+A\+D\+I\+L\+L\+O\+\_\+\+I\+N\+C\+L\+U\+D\+E\+\_\+\+D\+IR}; type {\ttfamily P\+A\+TH}; value {\ttfamily C\+:/mlpack/armadillo/include/}
\item Name\+: {\ttfamily A\+R\+M\+A\+D\+I\+L\+L\+O\+\_\+\+L\+I\+B\+R\+A\+RY}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value {\ttfamily C\+:/mlpack/armadillo/build/\+Debug/armadillo.lib}
\item Name\+: {\ttfamily B\+L\+A\+S\+\_\+\+L\+I\+B\+R\+A\+RY}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value {\ttfamily C\+:/mlpack/mlpack/packages/\+Open\+B\+L\+AS.0.\+2.\+14.\+1/lib/native/lib/x64/libopenblas.dll.\+a}
\item Name\+: {\ttfamily L\+A\+P\+A\+C\+K\+\_\+\+L\+I\+B\+R\+A\+RY}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value {\ttfamily C\+:/mlpack/mlpack/packages/\+Open\+B\+L\+AS.0.\+2.\+14.\+1/lib/native/lib/x64/libopenblas.dll.\+a}
\end{DoxyItemize}
\item If there is an error and Boost is not found, try \char`\"{}\+Add Entry\char`\"{} with the following variables and reconfigure\+:
\begin{DoxyItemize}
\item Name\+: {\ttfamily B\+O\+O\+S\+T\+\_\+\+I\+N\+C\+L\+U\+D\+E\+D\+IR}; type {\ttfamily P\+A\+TH}; value {\ttfamily C\+:/boost/}
\item Name\+: {\ttfamily B\+O\+O\+S\+T\+\_\+\+L\+I\+B\+R\+A\+R\+Y\+D\+IR}; type {\ttfamily P\+A\+TH}; value {\ttfamily C\+:/boost/lib64-\/msvc-\/14.2}
\end{DoxyItemize}
\item If Boost is still not found, try adding the following variables and reconfigure\+:
\begin{DoxyItemize}
\item Name\+: {\ttfamily Boost\+\_\+\+I\+N\+C\+L\+U\+D\+E\+\_\+\+D\+IR}; type {\ttfamily P\+A\+TH}; value {\ttfamily C\+:/boost/}
\item Name\+: {\ttfamily Boost\+\_\+\+P\+R\+O\+G\+R\+A\+M\+\_\+\+O\+P\+T\+I\+O\+N\+S\+\_\+\+L\+I\+B\+R\+A\+R\+Y\+\_\+\+D\+E\+B\+UG}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value should be {\ttfamily C\+:/boost/lib64-\/msvc-\/14.2/boost\+\_\+program\+\_\+options-\/vc142-\/mt-\/gd-\/x64-\/1\+\_\+71.\+lib}
\item Name\+: {\ttfamily Boost\+\_\+\+P\+R\+O\+G\+R\+A\+M\+\_\+\+O\+P\+T\+I\+O\+N\+S\+\_\+\+L\+I\+B\+R\+A\+R\+Y\+\_\+\+R\+E\+L\+E\+A\+SE}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value should be {\ttfamily C\+:/boost/lib64-\/msvc-\/14.2/boost\+\_\+program\+\_\+options-\/vc142-\/mt-\/x64-\/1\+\_\+71.\+lib}
\item Name\+: {\ttfamily Boost\+\_\+\+S\+E\+R\+I\+A\+L\+I\+Z\+A\+T\+I\+O\+N\+\_\+\+L\+I\+B\+R\+A\+R\+Y\+\_\+\+D\+E\+B\+UG}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value should be {\ttfamily C\+:/boost/lib64-\/msvc-\/14.2/boost\+\_\+serialization-\/vc142-\/mt-\/gd-\/x64-\/1\+\_\+71.\+lib}
\item Name\+: {\ttfamily Boost\+\_\+\+S\+E\+R\+I\+A\+L\+I\+Z\+A\+T\+I\+O\+N\+\_\+\+L\+I\+B\+R\+A\+R\+Y\+\_\+\+R\+E\+L\+E\+A\+SE}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value should be {\ttfamily C\+:/boost/lib64-\/msvc-\/14.2/boost\+\_\+program\+\_\+options-\/vc142-\/mt-\/x64-\/1\+\_\+71.\+lib}
\item Name\+: {\ttfamily Boost\+\_\+\+U\+N\+I\+T\+\_\+\+T\+E\+S\+T\+\_\+\+F\+R\+A\+M\+E\+W\+O\+R\+K\+\_\+\+L\+I\+B\+R\+A\+R\+Y\+\_\+\+D\+E\+B\+UG}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value should be {\ttfamily C\+:/boost/lib64-\/msvc-\/14.2/boost\+\_\+unit\+\_\+test\+\_\+framework-\/vc142-\/mt-\/gd-\/x64-\/1\+\_\+71.\+lib}
\item Name\+: {\ttfamily Boost\+\_\+\+U\+N\+I\+T\+\_\+\+T\+E\+S\+T\+\_\+\+F\+R\+A\+M\+E\+W\+O\+R\+K\+\_\+\+L\+I\+B\+R\+A\+R\+Y\+\_\+\+R\+E\+L\+E\+A\+SE}; type {\ttfamily F\+I\+L\+E\+P\+A\+TH}; value should be {\ttfamily C\+:/boost/lib64-\/msvc-\/14.2/boost\+\_\+unit\+\_\+test\+\_\+framework-\/vc142-\/mt-\/x64-\/1\+\_\+71.\+lib}
\end{DoxyItemize}
\item Once C\+Make has configured successfully, hit \char`\"{}\+Generate\char`\"{} to create the {\ttfamily .sln} file.
\end{DoxyItemize}
\end{DoxyItemize}\section{Additional Information}\label{build_windows_build_windows_additional_information}
If you are facing issues during the build process of mlpack, you may take a look at other third-\/party tutorials for Windows, but they may be out of date\+:

{\tt Github wiki Windows Build page}~\newline
 {\tt Keon\textquotesingle{}s tutorial for mlpack 2.\+0.\+3}~\newline
 {\tt Kirizaki\textquotesingle{}s tutorial for mlpack 2}~\newline
 