Skip to content

Building on Windows

Florian Kleemiß edited this page Nov 6, 2018 · 10 revisions

Cross Compilation

To obtain fully functional executables, which can even be copied between machines, the following cross compilation procedure was established:

On a Linux(ubuntu) machine, follow the instructions to obtain a copy from github and install all necessary go inside that folder. Additionally install the mingw_w64 package using:

sudo apt install mingw_w64

After that create a build directory and go there:

mkdir build && cd build

Use cmake to create the makefiles (replace w64 with w32 if you want to compile 32 bit system executables) and compile the executable. Unless you have an already cross-compiled version of BLAS/LAPACK then you will need to compile these too:

cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_w64.cmake -DCMAKE_BUILD_TYPE=RELEASE-STATIC -DCOMPILE_LAPACK=ON 
make -j

You should obtain tonto.exe, hart.exe and xtal.exe for use on the corresponding windows system.

PARALLEL VERSION

If you want to compile tonto with Microsoft-MPI you need to download the installers from Microsoft (msmpisdk.msi and MsMPISetup.exe, version 8.1 adn 9.0.1 tested) and install it on the windows machine you want to run it on. Then the folder C:\Program Files (x86)\Microsoft SDKs\MPI (Or wherever you installed it) will be needed on the linux machine you use for cross compilation. It should conatin at least a folder called Include and Lib. In the Include folder mv mpi.f90 to mpi.F90 and run x86_64-w64-mingw32-gfortran on it to obtain the mpi.mod file. In the Lib Folder navigate to x64 and copy msmpi.dll from System32 of your windows machine next to msmpi.lib. You will need to run the mingw-dlltool on these:

gendef msmpi.dll - generates msmpi.def

x86_64-w64-mingw32-dlltool -d msmpi.def -l libmsmpi.a -D msmpi.dll creates libmsmpi.a

If you want to take this to your compilation of tonto you need the following command:

cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_w64.cmake -DCMAKE_BUILD_TYPE=RELEASE-STATIC -Dmsmpi-linux-home=/path/on/the/cross/compilation/machine/where/Include_and_Lib/are -DMPI=ON -DCOMPILE_LAPACK=ON.. && make

This will compile tonto.exe and hart.exe. Even if there is an error for sbftool.exe, the other executables are fine. These executables can be tanken to windows machines and run by calling from a powershell or cmd.exe:

C:\Program Files\Microsoft MPI\Bin\mpiexec.exe -np 4 hart.exe

WARNING THE BELOW INFORMATION DOES NOT WORK BUT IS KEPT FOR REFERENCE PURPOSES

(from this revision on, it does work for at least one machine ...)

On Windows

The compilation procedure is similar to Linux, but you have to first install the MSYS2 minimal unix environment.

IMPORTANT: if you have a cygwin unix environment, please delete it before installing MSYS2. You will find cygwin as C:/cygwin or something like that. We have found that cygwin interferes with MSYS2.

Once you have MSYS2, open it's console; it has an "M" logo with a bit of purple.

Do not confuse it with the Microsoft console.

You can find MSYS2 in C:/mingw64.

In the MSYS2 console, first update the database :

pacman -Syu

Next, close the MSYS2 console, and open it again, then type

pacman -Su

If you are on an x86_64 machine (this is most likely) then install:

pacman -S mingw-w64-x86_64-toolchain

Else if you are on an ì686 machine then install:

pacman -S mingw-w64-i686-toolchain

Now install this stuff:

pacman -S base-devel
pacman -S perl
pacman -S git
pacman -S make
pacman -S mingw-w64-x86_64-cmake

Note that the make installed above is the MSYS2 make and not the GNU make.

Optional Compile and install the openblas library which includes lapack:

git clone "https://github.com/Alexpux/MINGW-packages"
cd MINGW-packages/mingw-w64-openblas
makepkg-mingw -sLf
pacman -U *.pkg.tar.xz 

The above will take a long time.

Finally, update the PATH variable by editing the .bashrc file e.g. using the vim editor.

Add the following line to the end of .bashrc :

export PATH=$PATH:/mingw64/bin

And source the file:

source ./.bashrc

Now clone the repository:

   git clone https://github.com/dylan-jayatilaka/tonto.git

To compile Tonto, first go into the tonto directory downloaded with git :

    cd tonto

Then make a build directory and go into that :

    mkdir build && cd build

Of course you can change build to be e.g. gfortran after the name of the compiler you use. Executables from different compilers or with different compilation options can be produced in build directories with different names. That's convenient.

On Windows use the MSYS2 Makefiles generator, and because numdiff is not available on windows we must use the slower perl script:

    cmake .. -G"MSYS Makefiles" -DCMP_SCRIPT=../scripts/compare_output.pl
    make -j