Installation/Windows/Cross-Compiling OpenFOAM 2.1.x in Linux For Windows with MinGW

From OpenFOAMWiki
< Installation‎ | Windows
Revision as of 13:29, 8 January 2013 by JLight (Talk | contribs)

Valid versions: OF Version 21x.png

1 Introduction

To Do

2 Packages Required to Cross-Compile OpenFOAM

To Do

3 Preparing To Cross-Compile

From here on it is assumed that the cross compilation is done in a folder, say for example `CrossCompiledOF', such that foamInstall that you normally set in OpenFOAM-2.1.x/etc/bashrc is:

foamInstall=/path/to/CrossCompiledOF

This path is referred as FOAM_INST_DIR to in OpenFOAM and the same is used in this article. However, please do not source OpenFOAM-2.1.x/etc/bashrc until you are asked. The environment variable FOAM_INST_DIR is used for convenience, you can obviously just the one without any issue.

export FOAM_INST_DIR=/path/to/CrossCompiledOF

3.1 Preparing OpenMPI

Install 64-bit OpenMPI on your Windows machine. It is also recommended that you install OpenMPI on your Linux machine used to cross-compile, this article is written with this assumption.

The installer for Windows is shown here (http://www.open-mpi.org/software/ompi/v1.6/downloads/OpenMPI_v1.6.2-2_win64.exe).

On your Windows machine copy the OpenMPI folder to a place where you can access it on your Linux Machine, like a USB drive, shared folder on VMs etc. This folder is located in "Program Files" or "Program Files (x86)" depending where you chose to install it (while installation the default is "Program Files (x86)"). Rename this folder as MSOPENMPI.

Copy this folder to your cross-compiling folder on linux.

 cp -vr /path/to/MSOPENMPI $FOAM_INST_DIR/.

3.2 Getting The Source

There are two options to get the source prepared:

  1. Clone the official repository, checkout the version used to generate the Symscape patch and patch the source
  2. Clone the repository maintained by J-Light at aims to keep up the official repository in terms of bug fixes.

The second may not always be the best option. After updating the code the only criteria used to push the source is if it compiles without any errors. If the first one is enough then go ahead and use it. However, if you need source from a more recent commit then use the repo maintained by J-Light.

To start off go to the build directory.

cd $FOAM_INST_DIR

3.2.1 Source: Official + Symscape Patch

  1. Clone the official repo using git
    git clone https://github.com/OpenFOAM/OpenFOAM-2.1.x.git
    git clone https://github.com/OpenFOAM/ThirdParty-2.1.x.git
  2. Get and extract the Symscape patch
    wget http://www.symscape.com/files/articles/openfoam21x-windows/v7-mingw-openfoam-2-1-x.patch.gz
    gzip -d v7-mingw-openfoam-2-1-x.patch.gz
  3. Checkout the correct version of OpenFOAM
    cd OpenFOAM-2.1.x
    git checkout -b Symscape 971882b657c1730e27a8df8dcf06e6d5e5a47991
  4. Check and apply patch
    git apply --check -p0 ../v7-mingw-openfoam-2-1-x.patch
    git apply -p0 ../v7-mingw-openfoam-2-1-x.patch

3.2.2 Source: Official + Symscape Patch + JLight updates

  1. Clone the required repos
    git clone -b Win64 git://github.com/J-Light/OpenFOAM-2.1.x.git
    git clone https://github.com/OpenFOAM/ThirdParty-2.1.x.git

3.3 Build Wmake

First we need to build wmake. To do so edit etc/bashrc. ( I use 'nano' to edit, you can change this to which ever you like)

nano $FOAM_INST_DIR/etc/bashrc

The following need to be edited

  1. Edit line foamInstall (line 45) such that
    foamInstall=/path/to/CrossCompiledOF
  2. Edit WM_MPLIB (line 84) to use the system openmpi.
    export WM_MPLIB=SYSTEMOPENMPI

Source the file

source $FOAM_INST_DIR/etc/bashrc

Build wmake

cd $WM_PROJECT_DIR/wmake/src
make

Symlink the folder containing the binary to the folder that will be searched during cross-compiling

cd $WM_PROJECT_DIR/wmake/platforms
ln -s linux64Gcc linux64mingw-w64

3.4 Getting Scotch

The ThirdParty-2.1.x folder only contains build scripts. The files for Scotch Library needs to be downloaded first. This can be done by

cd $WM_THIRD_PARTY_DIR
wget https://gforge.inria.fr/frs/download.php/28043/scotch_5.1.11.tar.gz
tar -xf scotch_5.1.11.tar.gz
ln -s scotch_5.1.11 scotch

4 Building The Scotch Library

Building Scotch is not straight forward. A bit of effort need to go into this.

  1. The first step is a bit well...odd, one can even say it is redundant (is a good chance it is, I do it because I need to check for other issues), however, I do not recommend skipping it. Build scotch like you would compile OpenFOAM in Linux.
    cp -vrf $WM_PROJECT_DIR/extra/scotch/src/Makefile .
    cp -vrf $WM_PROJECT_DIR/extra/scotch/src/libscotch/* $WM_THIRD_PARTY_DIR/scotch/src/libscotch/.
    cd $WM_THIRD_PARTY_DIR/scotch/src/libscotch
    make


    5 Building OpenFOAM

    6 Preparing the move to Windows

    --Nishit Joseph (talk) 14:08, 5 December 2012 (CET)