CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Announcements from Other Sources (
-   -   Cross-compiling OpenFOAM 1.6 on Linux for Windows 32 and 64bits with Mingw-w64 (

wyldckat November 13, 2009 08:21

Cross-compiling OpenFOAM 1.6 on Linux for Windows 32 and 64bits with Mingw-w64
Dear FOAMers and Windows users,

We at blueCAPE have worked on getting OpenFOAM 1.6 being cross-compiled to the fullest, from Linux to Windows, from and to either 32 or 64 bit architectures.
Thanks to the Mingw-w64 project, the MPICH2 project and Symscape's efforts on cross-compiling OpenFOAM since version 1.4.1, we have been able to make another step forward and making possible of getting OpenFOAM cross-compiled to the fullest, thus bringing parallel computing, libmetis and libscotch to the working grounds of Windows.

We've also worked on the, in order to bring you a detailed step by step guide to the patches available there. The patches were based on Symscape's version 3 for OpenFOAM 1.5.x, as well with the experience gathered when creating the patches available here and here.

Unfortunately, there still are some limitations to this cross-compiling version and we also haven't been able to fully test the resulting product, due to insufficient knowledge of all solvers and utilities that OpenFOAM has. These limitations are also described on the wiki here.

Also, these patches are still only for the version 1.6. Version 1.6.x will only be worked on if there is a need on our part or some auxiliary support in making these.

Hopefully, with these patches, as well as Symscape's patches, anyone can do the step of mixing the two together and coming up with updated versions. And there is a script named foamDiff, that can aid in making patches, without requiring to clean up the binaries and objects. This script was made because we didn't use the git version of OpenFOAM.

Also, we've tried to respect, to the best of our knowledge, the policies of the openfoamwiki. We added this page, added a link to this page and updated this section of the FAQ. We've tried to do the best we could, to give the up-to-date information there is on cross-compiled and natively compiled OpenFOAM versions for Windows.

We've also made some timings with the motorBike case from OpenFOAM 1.6.x, with single and dual core, 32 and 64bit, Linux and Windows (sorry, no Wine). Unfortunately, we probably didn't do a good job on getting a good mesh decomposition for the parallel runs, since the performance increase with dual core was only of about 30%.

Feel free to comment!

Best Regards and happy mass paralleling on Windows :)
Bruno Santos

akidess November 13, 2009 14:39

I'm not planning to use OpenFOAM on Windows in the near future, but nevertheless I'm impressed with your efforts, especially the exhaustive documentation you put up on the wiki. Thumbs up!

wyldckat November 15, 2009 00:32

Thank you Akidess!

But I'm still on a personal quest to improve upon what has already been done. I've been rattling my brain for solutions on how to get OpenFOAM built directly in Windows, without having to change substantially the code. But so far the best deduction I've come up with, was to use Cygwin's managed mounts to do the cross-compiling directly in Windows, and possibly also using Cygwin's git, but I still have to check if it's really possible.

And sadly, we at blueCAPE can't spend more time on this in the near future (already took a month), unless there is plausible reasons to do so :(

Best Regards,

soeren87 November 16, 2009 05:23

very good tutorial !

is it possible to build new solvers in windows directly ? Or do I have to build it in Linux and use the cross-compiler to make it windows compatible ?

wyldckat November 16, 2009 07:55

You can, but you'll have to port/tweak headers by hand
The big reason for having to resort to cross-compiling, is the fact that Windows is by default case-insensitive/case-preserving. And the headers of the OpenFOAM libraries are no exception, just look at the folder src/OpenFOAM/lnInclude, and you will find vector.H and Vector.H.
In the tutorial, this section explicitly lists the tutorials that have to be cross-compiled, for them to work in Windows.

Nonetheless, after cross-compiling the bulk of OpenFOAM, you can do some porting of just the headers for the libraries, and then use the native versions of mingw32/mingw-w64 gcc compilers. You could even remake the library ".a" objects files in Windows, just by using pexports and dlltool, as explained here. But the cross-compiled ".a" files might be enough.
The get-mpich2 script in the patches available in the tutorial, actually uses this for creating the .a files for MPICH2 x86_64! The pexports application is compiled explicitly by the build-mingw-w64 script, so you can use the code left from there to compile it for using in Windows.

But the tutorial and patches don't cover those issues... at least for now. I'm personally currently exploring the possibility of using Cygwin 1.7 for cross-compiling directly in Windows, but so far it seems about 2-3x slower than using Linux in a Virtual Machine. So, even if it works, it'll be more convenient, but much slower. Hopefully this week I'll managed to report on it.

wyldckat November 18, 2009 15:00


I'm personally currently exploring the possibility of using Cygwin 1.7 for cross-compiling directly in Windows, but so far it seems about 2-3x slower than using Linux in a Virtual Machine. So, even if it works, it'll be more convenient, but much slower. Hopefully this week I'll managed to report on it.
Well, after some testing, I've only managed to build up to libOpenFOAM.dll, not including it :(

Apparently Cygwin 1.7 is still too beta for it to work fully on this part. The make application jams on sorting the file dependencies for libOpenFOAM... looks like it stays put waiting for something...

Cygwin 1.5 has managed mounts, but their special compatibility system fails with loooooooong file paths, so no dice with this version.

So, in a nutshell, you will need:
- install the tools needed, just like in Linux;
- to switch the obcaseinsensitive flag to 0 in the Windows registry... reboot;
- in Cygwin, mount the OpenFOAM with posix=1;
- mount the /tmp with posix=1 too, for patch to work... and also do:

export TMP=/tmp
export TEMP=/tmp

- do:

ln -s /usr/lib/cpp /lib/cpp
- then do the rest like in the tutorial(s).

Oh, and mingw32 jams with a missing "langinfo.h" header file, that apparently cygwin doesn't have a proper one yet. But I did get a full cross-compiling gcc-mingw-w32 :D

Well... and that's that for now. As soon as Cygwin releases 1.7.1 officially... and I get the time to get around it... I'll post new results about it.

Ah, almost forgot: build timings... running the whole build-mingw-w32 script took 2h30 in Cygwin, and should take about 30-40min in Linux. I think the most guilty layer is the file interpretation system, but I'm not sure of it... since the software Comodo is installed and is a bit picky on what applications are doing with Windows and disks.

Best Regards,

wyldckat November 22, 2009 18:39

OpenFOAM+Cygwin+MSys+Windows = less Linux...
Fellow Foamers,

Thou who art binded to Windows, I give you the unholy grail of cross-compiling OpenFOAM directly in Windows, using Cygwin, now available on the wiki page here.
See the subsection "Advantages and Disadvantages with using Cygwin for cross-compiling" as to why you might want to do such a grueling thing ;)

Now, the only thing missing is for git to work properly in Cygwin 1.7... so OpenFOAM 1.6.x can also become a reality! Well, that and getting MinGW/MSys to do POSIX mounts on their own too...

Best regards,

wyldckat January 19, 2010 16:39

Wiki page updated, as well as patches
Greetings to all,

Just dropping by to report the latest updates to patches and the wiki page:
  • fixes made based on Symscape's version v9 for 1.6.x, because many of the solvers that use LES and RAS turbulence models need their libraries to be forced to load under Windows.
  • chtMultiRegionFoam now works, with KK instead of K for Windows builds.
  • Instructions on how to get OpenFOAM 1.6.x directly from repository using git under cygwin. (The problem wasn't from cygwin being in a beta stage :D)
  • reconstructParMesh wasn't being built because it wasn't in the respective Allwmake script.
  • Linking OpenFOAM to MPICH2 no longer requires Wine to work straight out of the boxed up patch.
  • Added link to tutorials that are known to work with these patches.
edit: Since I didn't want to steal the attention from the other announcers on this part of the forum, I've edited my last post to refer any questions related to this announced wiki page to this dedicated thread.

Best Regards,

All times are GMT -4. The time now is 13:05.