| Installation Guide

3. Tips for Installing on Windows

## 3.1 Windows with the Cygwin Toolset and Microsoft Visual C++

To compile and run Geant4 under Windows systems, some additional information and tools are required, although the installation produre is similar to that required on a UNIX based system. On Windows, the Cygwin toolset and the Microsoft Visual C++ compiler are used.
Cygwin32 is a UNIX development environment available for Microsoft Windows. You can freely obtain Cygwin32 from Cygwin or Cygwin/X.
We do not support direct use of Visual Studio; i.e. we do not provide Visual Studio workspace (.dsw) or project (.dsp) files, nor we do provide makefiles for the `nmake` application of MS Visual C++.

We use several of the tools provided by the Cygwin toolset:

- `make.exe` as a make tool
- `g++.exe` as a tool to analyse source file dependencies and create dependency (`.d`) files
- several other unix tools like `cp`, `mv`, `rm`, `touch`, etc.

At the installation of the Cygwin toolset it is therefore required to explicitely select some packages (i.e. gmake, gcc, binutils and tcsh from the "devel" category) in addition to those which are part of the default installation.
For more details on the toolset, please see the documentation available on the Cygwin pages. The User's Guide has quick start guides and help with setting up Cygwin with `setup.exe`.
Links to some installation tips for the Cygwin toolset and also "step by step" installation guides can be found in section 10.6 of the Application Developers Guide.

The usage of Cygwin32 for the build environment results in a build procedure similar to that on a UNIX system. The documentation in the User's Guide for Application Developers, Section 10.5, is largely applicable in this case.

The following steps are required to install geant4:

1. Install Cygwin (see also notes above):
   We do not depend on any specific feature of the version of Cygwin, so newer versions (or slightly older) are expected to work.
2. Set the environment for MS Visual C++, i.e. set the paths to libraries, include files, and executables for MS Visual C++. This can be done by modifying the start-up batch file `cygwin.bat` of Cygwin32 to include all the MSDOS commands found in the file `vcvars32.bat` provided in MS Visual C++ (in the VC++ .NET compiler installation directory, and usually located inside the `Common7/Tools` directory). This modification should be done after the installation of the Cygwin toolset, so that the environment gets properly set at the time of the invocation of the shell.
3. Unpack the source code into a directory of your choice.
4. Start the `Cygwin` shell from the start menu.
5. At this point you're ready to install Geant4. If manual installation is chosen, you must set the necessary environment variables. There are various ways to do so; for example through a command file for the Cygwin bash shell. This command file could be named `geant4-setup.sh`, and you must execute it with

       	. geant4-setup.sh

   including the leading dot and blank space. You could also have this as your `.bashrc` file. The commands in the command file should be:

       	# Set G4SYSTEM
       	export G4SYSTEM=WIN32-VC
       	#
       	# Set Path to CLHEP
       	export CLHEP_BASE_DIR=C:/usr/local
       	#
       	# --- Other optional settings
       	#Turn on verbose to show command used for compilation
       	#export CPPVERBOSE=1
       	#

   Note, in the example above, CLHEP was installed in `C:/usr/local`, therefore `include/CLHEP` and `lib/CLHEP.lib` must be included therein.
6. Once the environment is correctly set, the libraries are built using make from the `geant4/source` directory typing `make` from the `Cygwin bash` shell prompt.

Examples can be built in the same way as the libraries from examples/novice/N01, for instance: type `make` from the shell prompt.
Note that, depending on which external software is used, there may be some warnings in linking; e.g., we get `"unrecognized source file type -file.o-,object file assumed"`, or warnings of conflictings libraries. This often seems to be caused by an external library compiled for a different run time environment.

The binary of the example is placed by default into the `geant4/bin/WIN32-VC` directory. You may run it either from this directory or from the `examples/novice/N01` directory; sample input and output files are placed in each of the `examples/novice` directories. Some of the examples will need to read data files, and the place has to be given in environment variables again similar to the following example:

    	#
    	# Environment variables needed to find geant4 data files:
    	#
    	# Data for neutron scattering processes,
    	#    distributed in a separate tar file, then placed under data
    	export NeutronHPCrossSections=c:/usr/local/geant4/data/G4NDL
    	#
    	# Nuclear Photon evaporation data,
    	#    distributed with the source files under data
    	export G4LEVELGAMMADATA=c:/usr/local/geant4/data/PhotonEvaporation
    	#
    	# Data for radiative decay hadronic processes under data,
    	#    distributed in a separate tar file
    	export G4RADIOACTIVEDATA=c:/usr/local/geant4/data/RadiativeDecay
    	#
    	# Data for low energy electromagnetic processes,
    	#    distributed in a separate tar file, then placed under data
    	export G4LEDATA=c:/usr/local/geant4/data/G4EMLOW
    	#

All compiler and linker options are set in `config/sys/WIN32-VC.gmk`. If you require options different from our choice, you can modify this file.

## 3.2 Building Kernel Libraries DLLs

DLLs (Dynamic Link Libraries) on Windows are supported for .NET VC++ and can be built for the `compound` kernel libraries of Geant4 (see the Installation Procedure of this Guide for a dissertation on `global/compound` libraries).

The libraries can be built either manually, issuing the command:

            make dll

from the directory `$G4INSTALL/source` or by specifying it through the `Configure` script used for the installation.
Then, to build any application making use of the installed DLLs, the environment variable `G4LIB_USE_DLL` must be set in the environment.
Once the application is built, it is required to specify to the system the path where the DLLs are installed. To do so, add the absolute path (in Cygwin format) of the DLLs installation directory to the `PATH` variable; for example:

            export PATH=$PATH:/usr/local/geant4/lib/$G4SYSTEM

You may then be able to run successfully your application.

About the authors