Book Instal Guide
Book Instal Guide
Book Instal Guide
Geant4 Collaboration
Table of Contents
1. Installation Introduction .............................................................................................................. 1 1.1. Supported Computers and Operating Systems ...................................................................... 1 1.2. Required Software .......................................................................................................... 1 1.3. Visualization Software ..................................................................................................... 1 1.4. Software for Analysis and Histogramming ........................................................................... 2 2. Installation Procedures ............................................................................................................... 3 2.1. Using the Configure Script for installation ...................................................................... 3 2.2. Configuring the Environment to Use Geant4 ........................................................................ 4 2.3. Installing Geant4 Manually ............................................................................................... 4 2.3.1. Required Environment Variables ............................................................................. 4 2.3.2. Optional Environment Variables ............................................................................. 4 2.4. Integrating Geant4 into a Generic Framework ...................................................................... 6 3. Tips for Installing on Windows ................................................................................................... 7 3.1. Windows with the Cygwin Toolset and Microsoft Visual C++ ................................................. 7 3.2. Building Kernel Libraries DLLs ........................................................................................ 9 4. Using CMake to Build and Install Geant4 .................................................................................... 10 4.1. Prerequisite Software ..................................................................................................... 10 4.2. Building and Installing Geant4 with CMake ....................................................................... 10 4.2.1. Running CMake ................................................................................................. 11 4.2.2. Enabling Optional Components ............................................................................. 12 4.2.3. Building Geant4 from CMake Generated Buildscripts ................................................ 13 4.3. Using Geant4 ............................................................................................................... 13 4.4. Known Issues ............................................................................................................... 14
iii
Linux
- Scientific Linux CERN, SLC5 g++ gcc 4.1.2 MacOSX - MacOSX Darwin 10.6 g++ gcc 4.2.1 Windows - Windows XP and Cygwin32 MSVC++ 9.0, Visual Studio 2008
For a more detailed description of supported platforms/compilers and versions of third party software, please refer to the release notes available with the current release you're using in geant4/ReleaseNotes (also accessible from the web distribution page ).
Installation Introduction
WIRED4 JAS Plug-In ( HepRep Browser). Momo (a Java -based GUI environment, GGE, GPE, ...). VRML browser. Alternatively, you can produce an ascii file for VRML or DAWN. More information is available in Section 8.6, Visualization Drivers, of the User's Guide for Application Developers.
and follow the on-screen instructions. No system administrator privileges are required at this stage. The script will ask for the path in the system where the Geant4 libraries should be installed later on. The script provides default settings for most of the environment variables to be set. By pressing -RETURN-, the default values will be selected; otherwise the proper selection (or path, in case a path is requested) must be typed in. In case the installation procedure fails for some reason, or you realise the selected options were not correct at the time the installation started, you can repeat the whole process by manually removing the current installation with:
> cd geant4/source > make clean
where the $G4SYSTEM environment variable (specifying the kind of architecture and compiler used) is manually set in your environment (according to the flavors listed in Section 1.1). In case new modules must be added to an existing build (for example a module for visualization), this can be done manually by re-running Configure and providing the new settings. Once the process of building the libraries has been completed successfully, the Geant4 toolkit can be installed in the specified (already existing) installation area by typing:
> ./Configure -install
Libraries and necessary source code will be installed in lib/geant4, include/geant4 (if selected to install all headers in a single directory), src/geant4, respectively. System administrator privileges may be required for the installation stage, depending upon where in the system the installation should happen.
Installation Procedures
> $G4INSTALL/Configure
This will generate the shell script env.csh (env.sh for bash shell) to be sourced or integrated into the shell login script (.tcshrc or .bashrc). The shell script will be generated in the user's current directory ($PWD). The user can customize it to specify for example her/his proper working directory through the variable $G4WORKDIR. Once the generated script is sourced, the user will be ready to start building a Geant4 application. Refer to section the section Getting Started with Geant4 - How to Make an Executable Program of the Geant4 User's Guide for Application Developers for information on how to build an executable in Geant4.
Installation Procedures
G4DEBUG: flag specifying that libraries be built with debug symbols (requires a lot of disk space). The default is optimised-mode G4LIB_BUILD_SHARED: flag specifying that kernel libraries be built as shared libraries (libraries will then be used by default). If not set, static archive libraries are built by default G4LIB_BUILD_STATIC: flag specifying that kernel libraries be built as static archive libraries. Note that you may specify this flag in addition to G4LIB_BUILD_SHARED to build shared and static libraries simultaneously. G4LIB_BUILD_G3TOG4: flag specifying that the library for the g3tog4 module be built. By default the library will not be built. G4LIB_BUILD_ZLIB: flag specifying that an additional library for file compression should be built (not required on Linux/Unix systems, required on Windows if choosing OpenGL or OpenInventor visualization). By default the library will not be built. G4_NO_VERBOSE: defining this flag prevents the compilation of verbosity code (for better performance). The default is with verbosity on. The list of all additional flags (also requiring third-party packages installed) can be found in Section 5.2 of the Geant4 User's Guide for Application Developers . The Geant4 installation requires native STL (the Standard Template Library) as the base foundation class library. This also implies strict ISO-ANSI language compliance. In addition to the above, you might want to set the proper environment for visualization, such as: the kind of graphics driver(s) installed in the system the path to the installation of each graphics driver in case you want to build the Geant4 kernel libraries with the graphics drivers built-in. See Visualization - The Visualization Drivers of the Geant4 User's Guide for Application Developers . At this point, you may choose one of two ways to compile and install the kernel libraries, depending on your needs and system resources. From $G4INSTALL/source: 1. make This will make one library for each "leaf" category (maximum library granularity) and automatically produce a map of library use and dependencies. 2. make global This will make global libraries, one for each major category. The main advantage of the first approach is the speed of building the libraries and of the application, which in some cases can be improved by a factor of two or three compared to the "global library" approach. Using the "granular library" approach a fairly large number (roughly 90) of "leaf" libraries is produced. However, the dependencies and linking list are evaluated and generated automatically on the fly. The toplevel GNUmakefile in $G4INSTALL/source parses the dependency files of Geant4 and produces a file libname.map in $G4LIB. libname.map is produced by the tool liblist, whose source code is in $G4INSTALL/config. When building a binary application the script binmake.gmk in $G4INSTALL/config will parse the user's dependency files and use libname.map to determine through liblist the required libraries to add to the linking list. Only the required libraries will be loaded in the link command.
Installation Procedures
The command make libmap issued from $G4INSTALL/source, allows manual rebuilding of the dependency map. The command is issued by default in the normal build process for granular libraries. It is possible to install both "granular" and "compound" libraries, by typing "make" and "make global" in sequence. In this case, to choose usage of granular libraries at link time one should set the flag G4LIB_USE_GRANULAR in the environment; otherwise compound libraries will be adopted by default.
2.
3. 4. 5.
including the leading dot and blank space. You could also have this as your .bashrc file. The commands in the command file should be: 7
# 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 about 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 G4NEUTRONHPDATA=c:/usr/local/geant4/data/G4NDL # # Data for evaluated neutron cross-sections on natural composition of elements, # distributed in a separate tar file, then placed under data export G4NEUTRONXSDATA=c:/usr/local/geant4/data/G4NEUTRONXS # # Nuclear Photon evaporation data, # distributed with the source files under data export G4LEVELGAMMADATA=c:/usr/local/geant4/data/PhotonEvaporation # # Data for radio-active 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 # # Data for shell ionisation cross-sections, # distributed in a separate tar file, then placed under data export G4PIIDATA=c:/usr/local/geant4/data/G4PII # # Data for nuclear shell effects for INCL/ABLA hadronic model, # distributed in a separate tar file, then placed under data export G4ABLADATA=c:/usr/local/geant4/data/G4ABLA # # Data for measured optical surface reflectance in optical processes, # distributed in a separate tar file, then placed under data export G4REALSURFACEDATA=c:/usr/local/geant4/data/RealSurface #
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.
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
We call this directory the source tree. The CMake build enforces an out of source build so that the buildscripts generated by CMake do not mix with the actual Geant4 sources. This is particularly important for developers using a working copy from the geant4 repository, and also means you can build multiple configurations of Geant4 against one single source tree. You therefore need to build Geant4 in a separate directory which we call the build tree. This directory can be created wherever you like, though we strongly recommend it is outside the source tree. In addition, if you wish to use an IDE such as Eclipse, there may be limitations on the location of the build tree relative to the source tree. For these reasons, we recommmend creating your build tree directory alongside the source tree, e.g. using our location from above
/path/to/geant4.9.4 /path/to/geant4.9.4-build
10
Using CMake to Build and Install Geant4 You are of course free to experiment here, but the above is the recommended way. You may have as many build trees as you like.
The cmake command is the basic command line interface to CMake. All being well, you will see some platform dependent output (not complete)
$ cmake -DCMAKE_INSTALL_PREFIX=/install/location ../geant4.9.4 -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- setting default compiler flags for CXX -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done
CMake will then proceed to check for needed external packages. Assuming these are all installed correctly, then it should continue, giving the output (on Linux with GNU compiler)
---------Found CLHEP version: CLHEP 2.1.0.1 Found CLHEP: TRUE Geant4 backwards compatible system name: Linux Geant4 backwards compatible compiler name: g++ Geant4 backwards compatible variable G4SYSTEM : Geant4 backwards compatible variable G4INSTALL: Geant4 backwards compatible variable G4INCLUDE: Geant4 backwards compatible variable G4LIB : The following Geant4 features are enabled:
-- Configuring done -- Generating done -- Build files have been written to: /path/to/geant4.9.4-build
Depending on the speed of your computer and/or filesystem, there may be pauses at the Configuring and Generating stages as CMake actually writes out files. The detection of CLHEP relies on having the clhep-config script in the PATH, and if this is not the case on your system, you may see an error
11
If you see this error, you should either add the location of clhep-config to your PATH and re-run cmake as above, or re-run cmake and pass it the full path to clhep-config as
$ cmake -DCLHEP_CONFIG_EXECUTABLE=/full/path/to/clhep-config ../geant4.9.4
You should then see a successfull configuration as above. If you now list the contents of your build directory, it will contain something like
$ ls CMakeCache.txt CMakeFiles
cmake_install.cmake CPackConfig.cmake
CPackSourceConfig.cmake Makefile
outputs source
Here a Makefile has been created, and if you choose to use one of the other generators, different files will be visible.
12
Using CMake to Build and Install Geant4 It is strongly recommend to build global libraries. Granular libraries are only intended as a tool for Geant4 developers to cleanly debug and test their code.
$ make Scanning dependencies of target G4global [ 1%] Building CXX object source/global/CMakeFiles/G4global.dir/HEPNumerics/src/G4AnalyticalPolSolver.cc [ 1%] Building CXX object source/global/CMakeFiles/G4global.dir/HEPNumerics/src/G4ChebyshevApproximation ...
By default, CMake Makefiles produce a summary output of what's being built. If you wish to see more detail, you can run make with
$ make VERBOSE=1
which will output a very detailed report of everything being done. CMake Makefiles also support parallel builds, so you can also do
$ make -jN
where N should be selected based on the number of cores your machine has available. If there are errors in the build, make will immediately exit except in parallel mode where it will exit at the next branch point. You can also build parts of Geant4 selectively.
$ make help
will print a list of all targets that can be built. If the build is successful, you can run
$ make install
to install Geant4 under the location specified by CMAKE_INSTALL_PREFIX from earlier. As noted, this defaults to /usr/local on *NIX, so you will need to change it as described if you don't have write permission there. Note that you can also do a staged install using DESTDIR as
$ make install DESTDIR=/path/to/stage
If you are not using Makefiles, you will need to consult the documentation of your buildtool. However, CMake generally works by the book of these tools and so using the generated buildscripts should be straightforward.
13
Using CMake to Build and Install Geant4 CMAKE_INSTALL_PREFIX/share/geant4-9.4.0/config/geant4-9.4.0.sh CMAKE_INSTALL_PREFIX/share/geant4-9.4.0/config/geant4-9.4.0.csh which can be sourced or integrated into the shell rc scripts (.bashrc or .tcshrc). The scripts will configure your environment in the same way as described in Section 2.2, and Geant4 applications can then be built using the Geant4 supplied GNU makefile system. You should not directly edit the shell scripts to adjust variables such as G4WORKDIR. It is better to first source the script and then re-set any needed variables. You will also need to manually set the environment variables pointing to any needed data libraries. If you do not wish to, or cannot, use the Geant4 supplied GNU make system, a program CMAKE_INSTALL_PREFIX/bin/geant4-config is supplied. This can be executed to query the installation and extract needed compiler and linker flags to build an application using Geant4. Its usage is as follows
Usage: geant4-config [OPTION...] --prefix output installation prefix of Geant4 --version output version for Geant4 --libs output all linker flags --cflags output all preprocessor and compiler flags --libs-without-gui --cflags-without-gui output linker flags without GUI components output preprocessor and compiler flags without GUI components output yes if FEATURE is supported, or no if not supported
--has-feature FEATURE
Note that the elements in the Known Features section will display yes if a feature was enabled in the toolkit build. Note that this program will only be installed if global libraries are built.
14