Build mlpack on Windows using MinGW-w64

Automatic build

The build script combines the steps from below in a single batch file that will download and build the necessary packages in the folder where the batch file was executed. Just download the batch file from: https://kurg.org/mlpack-mingw-build.bat and run the script afterwards.

Build manually

1. Open Command Prompt

2. Set System Path for the follwing setup.

SET currentpath=%cd%
SET PATH=%currentpath%\mlpack\util\7z1806-extra;%currentpath%\mlpack\src\mingw64\bin;%currentpath%\mlpack\src\msys;%currentpath%\mlpack\src\msys\bin;%currentpath%\mlpack\util\cmake-3.13.3-win64-x64\bin\;%currentpath%\mlpack\bin;%PATH%

3. Create build directories.

if not exist %currentpath%"\mlpack" mkdir %currentpath%"\mlpack"
CD /D %currentpath%"\mlpack"

if not exist "util" mkdir "util"
if not exist "src" mkdir "src"
if not exist "lib" mkdir "lib"

4. Download 7zip, cmake, MinGW-w64, MSYS, OpenBLAS, boost, armadillo, mlpack

powershell -Command "(New-Object Net.WebClient).DownloadFile('https://kurg.org/data/7z1806-extra.zip', 'util\7zip.zip')"
call unzip -o %currentpath%"\mlpack\util\7zip.zip" -d %currentpath%"\mlpack\util\"

powershell -Command "(New-Object Net.WebClient).DownloadFile('https://kurg.org/data/cmake-3.13.3-win64-x64.zip', 'util\cmake-3.13.3-win64-x64.zip')"
call 7za x "%currentpath%\mlpack\util\cmake-3.13.3-win64-x64.zip" -o"%currentpath%\mlpack\util\" -y

powershell -Command "(New-Object Net.WebClient).DownloadFile('https://kurg.org/data/x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z', 'src\x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z')"
call 7za x "%currentpath%\mlpack\src\x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z" -o"%currentpath%\mlpack\src\" -y

powershell -Command "(New-Object Net.WebClient).DownloadFile('https://kurg.org/data/MSYS-20111123.zip', 'src\MSYS-20111123.zip')"
call 7za x "%currentpath%\mlpack\src\MSYS-20111123.zip" -o"%currentpath%\mlpack\src\" -y

powershell -Command "(New-Object Net.WebClient).DownloadFile('https://kurg.org/data/OpenBLAS-0.3.5.zip', 'src\OpenBLAS-0.3.5.zip')"
call 7za x "%currentpath%\mlpack\src\OpenBLAS-0.3.5.zip" -o"%currentpath%\mlpack\src\" -y

powershell -Command "(New-Object Net.WebClient).DownloadFile('https://kurg.org/data/boost_1_69_0.7z', 'src\boost_1_69_0.7z')"
call 7za x "%currentpath%\mlpack\src\boost_1_69_0.7z" -o"%currentpath%\mlpack\src\" -y

powershell -Command "(New-Object Net.WebClient).DownloadFile('https://kurg.org/data/armadillo-9.200.7.tar.xz', 'src\armadillo-9.200.7.tar.xz')"
call 7za x "%currentpath%\mlpack\src\armadillo-9.200.7.tar.xz" -o"%currentpath%\mlpack\src\" -y
call 7za x "%currentpath%\mlpack\src\armadillo-9.200.7.tar" -o"%currentpath%\mlpack\src\" -y
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://kurg.org/data/config.hpp', 'src\config')"

powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/mlpack/mlpack/archive/mlpack-3.0.4.zip', 'src\mlpack-3.0.4.zip')"
call 7za x "%currentpath%\mlpack\src\mlpack-3.0.4.zip" -o"%currentpath%\mlpack\src\" -y

4. Build OpenBLAS

CD /D %currentpath%\mlpack\src\OpenBLAS-0.3.5
make BINARY=64 DYNAMIC_ARCH=1 NUM_THREADS=64 USE_THREAD=1 USE_OPENMP=1 OPENBLAS_COMPLEX_STRUCT=1
make PREFIX=%currentpath%\mlpack install

5. Build mlpack boost dependencies

CD /D %currentpath%\mlpack\src\boost_1_69_0\tools\build
call bootstrap.bat gcc && b2 install --prefix=%currentpath%\mlpack\

CD /D %currentpath%\mlpack\src\boost_1_69_0
if not exist "build" mkdir "build"
call bjam install --toolset=gcc --with-serialization --with-program_options --with-math --with-test --with-random --layout=system optimization=full link=shared runtime-link=shared link=static threading=multi address-model=64 --stagedir=stage\x64 release stage --build-dir="%currentpath%\mlpack\src\boost_1_69_0\build" --prefix="%currentpath%\mlpack"

6. Build armadillo

CD /D %currentpath%\mlpack\src\armadillo-9.200.7
if not exist "build" mkdir "build"
CD /D %currentpath%\mlpack\src\armadillo-9.200.7\build
call cmake -G "MSYS Makefiles" -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc -DLAPACK_NAMES="%currentpath%\mlpack\lib\libopenblas.dll" DBLAS_LIBRARY="%currentpath%\mlpack\lib\libopenblas.dll" -DCMAKE_INSTALL_PREFIX="%currentpath%\mlpack" ..
call make
call make install
COPY /Y "%currentpath%\mlpack\src\config.hpp" "%currentpath%\mlpack\include\armadillo_bits\config.hpp"

7. Build mlpack

CD /D %currentpath%\mlpack\src\mlpack
if not exist "build" mkdir "build"
CD /D %currentpath%\mlpack\src\mlpack\build
cmake -G "MSYS Makefiles" -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc -DBLAS_LIBRARY="%currentpath%\mlpack\lib\libopenblas.dll.a" -DLAPACK_LIBRARY="%currentpath%\mlpack\lib\libopenblas.dll.a" -DCMAKE_INSTALL_PREFIX="%currentpath%\mlpack" ..
call make
call make install