Installing Geant4 on Windows

Prerequisites

To compile and use Geant4 under windows some additional tools are required. First you need Microsoft Visual Studio version 6 (with service pack 5 or later). This is commercial software that you will need to purchase and install. When installing Visual Studio you will be asked whether you want to allow it to modify your environment variables. I find it best to answer No to this question, and instead set the variables in my cygwin startup script (see below).

Secondly you will need to install cygwin, a Unix emulation layer for windows. The cygwin software is freely available from http://www.cygwin.com/. It can be quite tricky to install the correct components of the cygwin toolkit, but Norman Graf has written detailed installation instructions which are included on this CD. I find the easiest way to set up visual studio to run under cygwin is to modify my cygwin.bat file (normally in c:\cygwin) as follows:

@echo off

C:
chdir C:\cygwin\bin
call "C:\Program Files\Microsoft Visual Studio\VC98\Bin\vcvars32.bat"

bash --login -i

You may need to change the path to vcvars32.bat if you installed visual studio in a different location.

Finally you will need to install CLHEP. CLHEP is available on this CD here. (CLHEP is distributed as a .tgz file, you will need a tool like WinZip to unpack it). I assume in the following that you have unpacked CLHEP into c:\clhep.

Compiling Geant4

Now you are ready to unpack and install Geant4. Geant4 is available on this CD here. (Geant4 is distributed as a .zip file, you will need a tool like WinZip to unpack it). I assume in the following that you have unpacked CLHEP into c:\geant4\geant4_5_2_p02.

To compile and run Geant4 you will need to set several environment variables. I find the easiest way to do this is to create a simple script. My script (which I save in  c:\geant4\geant4_5_2_p02\geant4-setup.sh) contains:

# Set G4SYSTEM 
export G4SYSTEM=WIN32-VC
#
# Turn on debug flags, note that testing was done for the debug version only.
export G4DEBUG=1
# 
# Set Path to CLHEP
export CLHEP_BASE_DIR=c:/clhep
#
# --- Other optional settings
#Turn on verbose to show command used for compilation
#export CPPVERBOSE=1
#
export G4LIB_BUILD_STATIC=1
export G4INSTALL=c:/geant4/geant4_5_2_p02

Having created this script (with paths modified as necessary) you can start a cygwin shell, by clicking on the cygwin icon on your desktop:

Then issuing something like the following commands:

cd c:
cd geant4/geant4_5_2_p02
source geant4-setup.sh
cd source
make

All being well Geant4 should now compile. This can take an hour or more, depending on your CPU speed, but fortunately only has to be done once.

Once this is done you are ready to continue with the rest of the installation exercise.