Installation/Windows/Outdated/Using Cygwin for cross-compiling OpenFOAM
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 .
As of Cygwin 1.7 (now stable, since 23rd of December of 2009) managed mounts were dropped and POSIX mounts were introduced , as well as file paths increased to 4096 characters . The POSIX mount relies on a hidden feature of Windows , that enables NTFS POSIX compatibility system, also used by Interix's SFU/SUA , 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 ... 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:
- Download Cygwin 1.7 setup executable, available at www.cygwin.com.
- Run the setup program and install the following packages: autoconf automake binutils bison byacc dash diffutils patch doxygen flex gcc-core gcc-g++ git make python readline texinfo wget w3m libiconv
Other suggested packages: bzip2 gitk liblzma rxvt nano vim
NOTE:If you forget any package, run again this setup program, because it is how the packages for Cygwin are managed!
- Run (Winkey + R) regedit and set the following dword to 0:
- Reboot your Windows machine.
- Launch a Cygwin shell (either "Cygwin Bash Shell" or "rxvt" will do). At first run, it will setup your shell environment.
- 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/bashto
John Smith:unused:1023:553:MACHINE\John Smith,S-2-8-41-4232284298-346061587-833252115-1023:/home/jsmith:/bin/bash
- Now close the previous shell window and start a new one. Do:
mkdir OpenFOAM echo export TEMP=/tmp >> ~/.bashrc echo export TMP=/tmp >> ~/.bashrc
- 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 0In 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!
- Close the old shell window and open a new one, so changes are applied. Do:
ln -s /usr/bin/cpp /lib/cppThis is required for wmake to work properly.
- This one is a bit ironic... although dash is faster than bash, which makes it possible to build OpenFOAM faster, but it will currently make it virtually impossible to build the cross-compilers. Therefore, it's best to at least replace the default sh with bash at least for building the cross-compilers:
cp /bin/bash /bin/sh
To later on undo this, run:
cp /bin/dash /bin/sh
- Edit the ~/.bashrc file (either with Cygwin's nano or Notepad2 mentioned above) and add the following text:
#take care of annoying Windows user naming - necessary for OpenFOAM's bashrc script to work properly export USERNAME=jsmith export USER=$USERNAME #the next three items are attempts for accelerating Cygwin # eliminate long Window$ pathnames from the PATH export PATH='/bin:/usr/bin:/usr/local/bin' # check the hash before searching the PATH directories shopt -s checkhash # do not search the path when .-sourcing a file shopt -u sourcepathSave and close.
- Run the following two commands in Cygwin's terminal to upgrade its RAM limit up to 1.5GB of RAM (don't use less than 1.3GB):
regtool -i set /HKLM/Software/Cygwin/heap_chunk_in_mb 1536 regtool -v list /HKLM/Software/CygwinKeep in mind that you will also need 1.5GB of system's RAM or more!
- With dash installed, run this command:
cp /bin/dash /bin/shThis way, including the tweaks above, you get a somewhat faster build process.
- Reboot Cygwin once again (close all Cygwin related terminals and/or XWindows).
- 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 ( patches only). Find:
# Detect system type and set environment variables appropriately # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ export WM_ARCH=`uname -s` case $WM_ARCH in Linux) WM_ARCH=linuxand 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 allIn 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:
- Cygwin for development (for execution, lacks a proper path translation for the resulting cross-compiled OpenFOAM applications);
- MSys for using OpenFOAM scripts and applications, thus having a near Linux experience with OpenFOAM;
- 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 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 git config --global core.autocrlf false
And then you can do a git clone:
cd $HOME/OpenFOAM git clone git://repo.or.cz/OpenFOAM-1.6.x.git
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
- 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 3-6GB 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 linking 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 the usual patches and you will have to deal with the overhead of Cygwin's translation layer.
- Various Linux IDEs (including QtCreator, Anjuta, KDevelop, Code::Blocks, Geany, Kate and many others) are already available for Cygwin 1.7: see Cygwin ports.
- Your Windows system might become unstable, although it seemed unlikely so far (Wyldckat 22 July 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 will still be able to edit files with Windows editors, as long as there aren't two similar files on the same folder. Examples:
- No Eclipse CDT  is known that it will work under Cygwin in Windows, since it relies on Sun's JRE... and JRE in Windows is case insensitive, because Windows is by default also insensitive to file name case. But it should be able to handle most of the source code files and help with debugging, up to the point where it is unable to handle the name clashes...
- Microsoft's Visual Studio is also case insensitive in file names, which would hinder the ability to, at the very least, debug applications that link to OpenFOAM libraries along with the applications source code; at least without re-engineering the OpenFOAM C++ headers. Additionally, Visual Studio usually doesn't keep up with the same C/C++ standards that gcc does, so it's very hard to get it to even, if the file sensitivity issues are fixed.
- It is about 2 times slower to cross-compile OpenFOAM for Windows in Cygwin, than in Linux (even if virtualization is used, when used along with CPU VT support!). It's also 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.
Wyldckat 18:55, 4 September 2010 (CEST) - Added tuning information for speeding up Cygwin. Minor typo fixes and some other miscellaneous information added.
Wyldckat 15:32, 22 July 2010 (UTC) - Updates made to the content.
Wyldckat 11:56, 22 July 2010 (UTC) - Moved from Cross Compiling OpenFOAM in Linux For Windows with MinGW.