Difference between revisions of "Installation/Windows/Outdated/Using Cygwin for cross-compiling OpenFOAM"

From OpenFOAMWiki
(Notes on using Cygwin)
(Working with OpenFOAM 1.6.x and Cygwin)
Line 46: Line 46:
 
</ul>
 
</ul>
  
= Working with OpenFOAM 1.6.x and Cygwin =
+
= Working with OpenFOAM git versions and Cygwin =
Although the patches listed on this page are for OpenFOAM 1.6, you can actually use git in Cygwin and use the [http://www.symscape.com/openfoam-1-6-x-on-windows patches available by Symscape].
+
Although the patches listed on the [[Tip Cross Compiling OpenFOAM in Linux For Windows with MinGW|Cross Compiling OpenFOAM 1.6 in Linux For Windows with MinGW]] page are for OpenFOAM 1.6 and 1.7, you can actually use git in Cygwin and use the [http://www.symscape.com/openfoam-1-6-x-on-windows patches available by Symscape].
 
You will have to configure the global variables for git like this:
 
You will have to configure the global variables for git like this:
 
<bash>git config --global core.ignorecase false
 
<bash>git config --global core.ignorecase false
Line 53: Line 53:
 
git config --global core.symlinks true</bash>
 
git config --global core.symlinks true</bash>
 
And then you can do a '''git clone''':
 
And then you can do a '''git clone''':
 +
<ul><li>{{version1.6}}
 
<bash>cd $HOME/OpenFOAM
 
<bash>cd $HOME/OpenFOAM
git clone git://repo.or.cz/OpenFOAM-1.6.x.git</bash>
+
git clone git://repo.or.cz/OpenFOAM-1.6.x.git</bash></li>
And so you have the most recent OpenFOAM 1.6.x source code available directly in your Windows machine, without the need of a second machine with Linux.
+
<li>{{version1.7}}
If you do a manual cross-over of the patches given here and the ones by Symscape, you will be able to cross-compile the latest OpenFOAM 1.6.x, without massive re-engineering of the OpenFOAM source code under Windows.
+
<bash>cd $HOME/OpenFOAM
 +
git clone git://github.com/OpenCFD/OpenFOAM-1.7.x.git</bash></li></ul>
 +
 
 +
And so you have the most recent OpenFOAM git version source code available directly in your Windows machine, without the need of a second machine with Linux.
 +
If you do a manual ''cross-over'' of the patches given here and the ones by Symscape, you will be able to cross-compile the latest OpenFOAM version, without the need to do a massive re-engineering of the OpenFOAM source code under Windows.
  
 
= Advantages and Disadvantages with using Cygwin for cross-compiling =
 
= Advantages and Disadvantages with using Cygwin for cross-compiling =

Revision as of 15:18, 22 July 2010

1 Introdution

In Cygwin 1.5, managed mounts were introduced. After some testing, it was discovered that OpenFOAM has some very long path names, which aren't handled properly by Cygwin's managed mounts, due to path size limit [1].

As of Cygwin 1.7 (now stable, since 23rd of December of 2009) managed mounts were dropped and POSIX mounts were introduced [2], as well as file paths increased to 4096 characters [3]. The POSIX mount relies on a hidden feature of Windows [4], that enables NTFS POSIX compatibility system, also used by Interix's SFU/SUA [5], thus enabling full case sensitivity for files.

In other words, as of Cygwin 1.7, it is possible to compile and cross-compile OpenFOAM directly in Windows, without major reconstruction of the files and structure of the source code. Nonetheless, the whole build system has to be done under Cygwin's layer, because the flag obcaseinsensitive doesn't actually make all of Windows applications aware of full file name case sensitivity.

CAUTION: following the steps on this section, could make your Windows installation unstable [6]... use at your own risk! In case you find file names that differ only in letter case, these will only be accessible by using Cygwin's shell. (So far by my experience, only the file system got a bit slower - Wyldckat 19 January 2010 (UTC))

2 Setting it up

So, without further ado, here is the step-by-step on setting it all up:

  1. Download Cygwin 1.7 setup executable, available at www.cygwin.com.
  2. Run the setup program and install the following packages: autoconf automake binutils bison byacc diffutils patch doxygen flex gcc-core gcc-g++ git make python readline texinfo wget
    Other suggested packages: bzip2 gitk liblzma rxvt vim
    NOTE:If you forget any package, run again this setup program, because it is how the packages for Cygwin are managed!
  3. Run (Winkey + R) regedit and set the following dword to 0:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\kernel\ObCaseInsensitive
  4. Reboot your Windows machine.
  5. Launch a Cygwin shell (either "Cygwin Bash Shell" or "rxvt" will do). At first run, it will setup your shell environment.
  6. Now, your home folder must have been also created, based on your Windows user name. In case your user name has spaces in it, edit the file /etc/passwd (either with vim or with a Windows editor with UTF8 editing capability (I recommend Notepad2 - Wyldckat)) and edit the line that has your user name. For example, for John Smith, change:
    John Smith:unused:1023:553:MACHINE\John Smith,S-2-8-41-4232284298-346061587-833252115-1023:/home/John Smith:/bin/bash
    to
    John Smith:unused:1023:553:MACHINE\John Smith,S-2-8-41-4232284298-346061587-833252115-1023:/home/jsmith:/bin/bash
  7. Now close the previous shell window and start a new one. Do:
    mkdir OpenFOAM
    echo export TEMP=/tmp >> ~/.bashrc
    echo export TMP=/tmp >> ~/.bashrc
  8. Create two folders on your harddrive, one to work as the base of your OpenFOAM installation, another to be a folder for temporary data. Edit the file /etc/fstab and add two lines, similar to these:
    D:/o /home/jsmith/OpenFOAM ntfs binary,posix=1 0 0
    D:/dump /tmp ntfs binary,posix=1 0 0
    In this example, D:/o is the folder where OpenFOAM will be installed for real, and D:/dump is the folder for temporary files. The latter is needed for the application patch to work properly!
    NOTE: Try to keep names short, so there won't be problems down the road with path names that are too long!
  9. Close the old shell window and open a new one, so changes are applied. Do:
    ln -s /usr/bin/cpp /lib/cpp
    This is required for wmake to work properly.
  10. Now... now just follow the instructions from the start of the cross-compiling tutorials: Tip Cross Compiling OpenFOAM in Linux For Windows with MinGW.

3 Notes on using Cygwin

Things to keep in mind, while following the tutorials:

  • Edit the OpenFOAM files $WM_PROJECT_DIR/etc/bashrc* before launching them. Find:
    # Detect system type and set environment variables appropriately
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    export WM_ARCH=`uname -s`
     
    case $WM_ARCH in
    Linux)
        WM_ARCH=linux
    and change Linux) to *). This way, the environment will be set in Cygwin as if it were Linux.
  • Before running ./Allwmake, do first:
    cd $WM_PROJECT_DIR
    wclean all
    In order to remove old lnInclude links, because Cygwin isn't 100% like Linux.
  • On the chapter "Copying the files to your Windows installation" (versions: 1.6, 1.7), on the step about DOS_Mode.bat, you just need to copy/move the two batch files to the base installation of OpenFOAM ($HOME/OpenFOAM). You'll only need to edit the user name and whether to use dummy or MPICH2. But most importantly, on that chapter... you no longer need to pack and leave, because you are already here!
  • If you want to use the original scripts of OpenFOAM, you can setup an MSys environment that mounts similarly to your Cygwin /etc/fstab, and edit your home folder and user name at the MSys installation, and you will have a triple environment in Windows, that uses the same OpenFOAM folder:
    1. Cygwin for development (for execution, lacks a proper path translation for the resulting cross-compiled OpenFOAM applications);
    2. MSys for using OpenFOAM scripts and applications, thus having a near Linux experience with OpenFOAM;
    3. DOS_Mode.bat for having a Windows Command Line and going old-DOS-school.

4 Working with OpenFOAM git versions and Cygwin

Although the patches listed on the Cross Compiling OpenFOAM 1.6 in Linux For Windows with MinGW page are for OpenFOAM 1.6 and 1.7, you can actually use git in Cygwin and use the patches available by Symscape. You will have to configure the global variables for git like this:

git config --global core.ignorecase false
git config --global core.fileMode true
git config --global core.symlinks true

And then you can do a git clone:

  • OF version 16.png
    cd $HOME/OpenFOAM
    git clone git://repo.or.cz/OpenFOAM-1.6.x.git
  • OF version 17.png
    cd $HOME/OpenFOAM
    git clone git://github.com/OpenCFD/OpenFOAM-1.7.x.git

And so you have the most recent OpenFOAM git version source code available directly in your Windows machine, without the need of a second machine with Linux. If you do a manual cross-over of the patches given here and the ones by Symscape, you will be able to cross-compile the latest OpenFOAM version, without the need to do a massive re-engineering of the OpenFOAM source code under Windows.

5 Advantages and Disadvantages with using Cygwin for cross-compiling

Advantages:

  • You can develop and execute all directly in Windows, without having to go back and forth from/to Linux.
  • Save disk space (at least, 3GB for Linux installation plus 3GB for development of OpenFOAM).
  • Faster development process, including debugging where necessary (either old school or GDB with MinGW/MSys).
  • Use the same tools used in Linux to build OpenFOAM, so no need to create project files or makefiles.
  • You still get a MinGW build of OpenFOAM, without link to Cygwin, thus removing the overhead of Cygwin.
  • If you want OpenFOAM applications that are fully case sensitive under Windows, you can do it if you build it under Cygwin! Although, the necessary changes aren't available with these patches and you will have to deal with the overhead of Cygwin's translation layer.

Disadvantages:

  • Your Windows system might become unstable, although it seemed unlikely so far (Wyldckat 19 January 2010 (UTC)).
  • Using an IDE for code development, will require that the IDE is re-compiled (not cross-compiled) under Cygwin, with full file name case sensitivity turned on, in order to be able to fully access all files. Although you still will be able to edit files with Windows editors, as long as there aren't two similar files on the same folder.
  • It is about 2 times slower to cross-compile OpenFOAM for Windows in Cygwin, than in Linux (even if virtualization is used!), and 2 to 3 times slower to build the cross-compilers. So, you will need a quad-core machine in Windows+Cygwin, while you only need dual-core machine in Linux, to achieve nearly the same building speed.

6 History

Wyldckat 11:56, 22 July 2010 (UTC) - Moved from Cross Compiling OpenFOAM in Linux For Windows with MinGW. NOTE: still have to update the contents...