GENIE WindowsCompilation

From SourceWiki
Revision as of 00:53, 18 March 2008 by Genie-user (talk | contribs)
Jump to navigation Jump to search

Building GENIE on Windows Platforms

The GENIE makefiles have been modified to enable a command line compilation of the framework under Windows using Linux emulation software.

Prerequisites

In order to build GENIE on a Windows platform you will need to install and configure a suitable environment consisting of

  • A linux emulator
  • Third party libraries including NetCDF
  • A Windows Fortran compiler
  • A Windows Linker

The build system is known to work with the following software:

Tool Software Versions Notes
Linux emulation CygWin 1.5.12-1  
MinGW (MSYS) 1.0.10 Build only. There is no bash shell available so genie_example.job cannot be executed.
Third party libraries NetCDF 3.5.0, 3.6.0, 3.6.1, 3.6.2 Pre-built dll from UCAR can be used with the native microsoft compilers. We recommend building the NetCDF library locally.
Python 2.3.3+ Available in CygWin. Must be installed separately for MinGW.
Native Microsoft Fortran Compiler Compaq Visual Fortran 6.6C  
Intel Visual Fortran 9.1, 10.0, 10.1  
C/C++ Compiler / Linker Microsoft Visual Studio .NET 2003 7.1.3088  
Microsoft Platform SDK for Server 2003 R2  
Microsoft Visual Studio 2005 8.0.50727.762  
GNU Compilers Fortran Compiler GNU g95 0.91  
GNU gFortran 4.3.0  
C/C++ Compiler / Linker GNU gcc 4.0.3  
GNU ld 2.16.91  

Installing a Linux Emulator

In order to execute the GENIE build process on a Windows platform it is necessary to install a Linux emulator that can process the GNU make files. There are two popular Linux emulation tools for Windows; Cygwin and MinGW. Cygwin provides a comprehensive Linux emulation layer for Windows and can be used to build, execute and manage GENIE. MinGW (Minimalist GNU for Windows) provides a limited set of tools that are sufficient to build GENIE but cannot be used to configure the model for execution. We therefore recommend the Cygwin route but provide details of MinGW for completeness.

Cygwin installation

Download the Cygwin setup executable from the Cygwin website at http://cygwin.com/. Execute the setup program and install Cygwin as directed. When asked to select packages please ensure that the following packages are installed:

  • Base -> bash
  • Devel -> make
  • Interpreters --> python
  • Interpreters --> perl (for documentation)
  • gfortran specific requirements
    • Math --> gmp
    • Math --> mpfr

Native Win32 Compiler Configuration

We assume that you have a standard installation of the Intel or Compaq Visual Fortran product on your system. In order to make the compiler and linker available at the command line within the Cygwin shell we recommend editing the batch file that launches Cygwin as follows. Edit the file <cygwin>/cygwin.bat (adjusting the paths to the compilers as appropriate):

Compaq Visual Fortran

@echo off

call "C:\Program Files\Microsoft Visual Studio\DF98\BIN\DFVARS.BAT"
call "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32.bat"

C:
chdir C:\cygwin\bin

bash --login -i

Intel Visual Fortran

@echo off

call "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\SetEnv.Cmd" /XP32 /RETAIL
call "C:\Program Files\Intel\Compiler\Fortran\9.1\ia32\Bin\IFortVars.bat"

C:
chdir C:\cygwin\bin

bash --login -i

GNU g95 Compiler Installation

For up to date details please see http://ftp.g95.org/#Win. Download g95-x86-cygwin.tgz from http://ftp.g95.org/g95-x86-cygwin.tgz. Copy this file to the root of your cygwin distribution. In cygwin:

 cd /
 tar zxvf g95-x86-cygwin.tgz

GNU gFortran Compiler Installation

For up to date details please see http://gcc.gnu.org/wiki/GFortranBinariesCygwin. Download the latest release of the compiler. A link to the location of the latest release can be found at http://gcc.gnu.org/wiki/GFortranBinaries. Move the release archive to the Cygwin root directory. In Cygwin:

 cd /
 tar jxvf gfortran-4.3-Cygwin-i686.tar.bz2
 ln -s /usr/local/gfortran/bin/gfortran.exe /usr/local/bin/gfortran
 ln -s /usr/local/gfortran/bin/gfortran.exe /usr/local/bin/gfc

MinGW installation

MinGW http://www.mingw.org/ provides a build environment capable to generating Windows executables that do not rely on 3rd party dlls.

Building NetCDF

Download NetCDF source release from UCAR:

 http://www.unidata.ucar.edu/downloads/netcdf

Extract the contents of the archive to a convenient location <netcdf_root>.

Microsoft Compilers

The GENIE framework requires a full installation of the NetCDF library including the C, F77, F90 and C++ interfaces (although the latter is only required for the nightly build tests and can be omitted if these will not be run). The UCAR website does not currently (August 2005) provide pre-built binaries for Win32 satisfying these requirements so we must build the libraries manually.

Download the NetCDF source code from the UCAR website:

ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf.tar.gz

Extract the contents of the archive to a local directory. Open the src\win32\NET\netcdf.sln file with Microsoft Visual Studio. Open the Configuration Manager and set the Active Solution to "Release". Highlight the netcdf project and open the properties dialog. Select C/C++ -> Command Line and add the following compiler option in the Additional Options dialog:

 /D FCALLSC_QUALIFIER="__declspec(dllexport) __stdcall"

This compiler directive causes the F77 interface to be built in addition to the default C interface. Build the solution and close Visual Studio.

Open a Command Prompt and configure the CVF and the VC++.NET environments (modify the paths to your local installation if necessary):

 "C:\Program Files\Microsoft Visual Studio\DF98\BIN\DFVARS.BAT"
 "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32.bat"

Navigate to the src\f90 directory and build the F90 library:

 Compaq Visual Fortran:
 f90.exe /compile_only typeSizes.f90
 f90.exe /compile_only netcdf.f90
 lib /OUT:netcdf_f90.lib typeSizes.obj netcdf.obj
 Intel Visual Fortran:
 ifort.exe /iface:cvf /compile-only typeSizes.f90
 ifort.exe /iface:cvf /compile-only netcdf.f90
 lib /OUT:netcdf_f90.lib typeSizes.obj netcdf.obj

The Win32 build of the C++ interface is not officially supported by UCAR (at least no specific documentation exists on this). Unfortunately, we require a 'hack' to the code to get the C++ interface to build using Visual Studio. Create a copy of the netcdf.h header file:

 copy src\libsrc\netcdf.h src\cxx\netcdf.h

Edit the new copy of netcdf.h in src\cxx and comment out line 199 (line number may vary between releases)

 // #define off_t __int64

Navigate to the src\cxx directory and build the C++ library:

 netcdf-3.6.0-p1:
 cl.exe /c /O2 /I..\libsrc /DNDEBUG /D "DLL_NETCDF" /EHsc netcdf.cpp
 cl.exe /c /O2 /I..\libsrc /DNDEBUG /D "DLL_NETCDF" /EHsc ncvalues.cpp
 lib /OUT:netcdf_c++.lib netcdf.obj ncvalues.obj
 netcdf-3.6.1:
 cl.exe /c /O2 /I..\libsrc /I..\win32\NET /DNDEBUG /D "DLL_NETCDF" /EHsc netcdf.cpp
 cl.exe /c /O2 /I..\libsrc /I..\win32\NET /DNDEBUG /D "DLL_NETCDF" /EHsc ncvalues.cpp
 lib /OUT:netcdf_c++.lib netcdf.obj ncvalues.obj

Unfortunately, we have to create our own installation. Please create directories and copy files as indicated below. Use the command prompt or Windows Explorer according to preference.

cd <netcdf_root>		(contains the src folder)
[cut-and-paste should work for the commands below]

mkdir bin
mkdir lib
mkdir include

copy src\win32\NET\Release\netcdf.dll bin\
copy src\win32\NET\Release\ncdump.exe bin\
copy src\win32\NET\Release\ncgen.exe bin\

copy src\win32\NET\Release\netcdf.lib lib\
copy src\f90\netcdf_f90.lib lib\
copy "src\cxx\netcdf_c++.lib" lib\

copy src\libsrc\netcdf.h include\
copy src\fortran\netcdf.inc include\
copy src\f90\netcdf.mod include\
copy src\f90\typeSizes.mod include\
copy src\cxx\netcdf.hh include\
copy src\cxx\netcdfcpp.h include\
copy src\cxx\ncvalues.h include\

GNU Compilers

In a Cygwin environment that has g95 installed, navigate to the NetCDF directory (here <netcdf_root_cygpath> refers to the location of the NetCDF root in the Cygwin path style. e.g. /cygdrive/c/netcdf-3.6.2).

 cd <netcdf_root_cygpath>

g95 Compiler

 FC=g95 ./configure --prefix=<netcdf_root_cygpath>
 make check
 make install

gfortran Compiler

 FC=gfortran CPPFLAGS=-DpgiFortran ./configure --prefix=<netcdf_root_cygpath>
 make check
 make install

NB. If the configure phase fails indicating that the f90 compiler is not working then please check that you have installed the Math packages GMP and MPFR into Cygwin.

Building GENIE

I strongly recommend checking out the GENIE code into a directory that does not contain any space characters. We have not tested builds with paths containing spaces, they may or may not work. Life is simpler without the spaces.

Native Microsoft Compilers

Edit user.sh:

 CODEDIR=/cygdrive/drive_letter/path/to/genie
 OUTROOT=/cygdrive/drive_letter/path/to/output

Edit user.mak:

 GENIE_ROOT=/cygdrive/drive_letter/path/to/genie
 OUT_DIR=/cygdrive/drive_letter/path/to/output

Select the appropriate Windows version of the GNU compiler:

 Either:
 F77=f90.exe
 Or:
 F77=ifort.exe

And set the other relevant flags

 CXX=cl.exe
 MACHINE=WIN32
 NETCDF_DIR=E:\\users\\andrew\\netcdf-3.6.0-p1
 NETCDF_NAME=netcdf.lib

Change the path as appropriate for the location of your Win32 NetCDF installation.

At the CygWin bash prompt make sure that the NetCDF DLL and Python are in the system path:

 $ export PATH=$PATH:/cygdrive/c/netcdf/bin:/cygdrive/c/Python23

It is worth checking that Python can be invoked from the shell and that the version is >1.5.2. To build the binary it should be possible to execute the make command:

 $ cd [install-path]/genie-main
 $ make

The following warning message will be issued during the final link phase of the build:

 LINK : warning LNK4044: unrecognized option "module:..\genie-lib\mod"; ignored

This is an expected outcome and does not impact the final production of the GENIE binary.

GNU Compilers

Edit user.sh:

 CODEDIR=/cygdrive/drive_letter/path/to/genie
 OUTROOT=/cygdrive/drive_letter/path/to/output

Edit user.mak:

 GENIE_ROOT=/cygdrive/drive_letter/path/to/genie
 OUT_DIR=/cygdrive/drive_letter/path/to/output

Select the appropriate Windows version of the GNU compiler:

 Either:
 F77=g95.exe
 Or:
 F77=gfc.exe

And set the other relevant flags (please note that despite being a Windows build this is identical to a Linux setup)

 CC=gcc
 CXX=g++
 MACHINE=LINUX
 NETCDF_DIR=<netcdf_root_cygwin>
 NETCDF_NAME=netcdf