Here is the information that I wish I knew when first attempting to build geant4.6.2.p01 from the source files on my linux box.


Note: As geant4 continues to evolve, these directions will likely become outdated.

There are helpful instructions on the geant4 site for building geant4.6.2.p01.

I have using a copy of fermi linux which is similar the Redhat Enterprise package. (See the fermilinux FAQ for more details.) I am using gcc version 3.2.2.

  • Go to the geant4 download area.
  • Download the 'Source files' (I used the 'Unix tar format') after reading the license conditions and release notes. Download the 5 'Data files': G4NDL3.7.tar.gz, G4EMLOW2.3.tar.gz, PhotonEvaporation.2.0.tar.gz, RadiativeDecay.3.0.tar.gz, and Elastic.1.0.tar.gz. Also, download CLHEP version 1.8.1.0.
  • There are a number of environmental variables that must be set before geant4 can be installed. Example scripts that set most of the environmental variables can be found under the 'Get Ready to Compile' section of instructions link at the top of the page. Since I am using bash, I created a setup-geant4.sh script in my /usr/local directory. I found that a couple other variables needed to be set. I added export G4LISTS_BASE=$G4INSTALL/hadronic_lists (setenv G4LISTS_BASE $G4INSTALL/hadronic_lists if you are using tcsh or csh) to the setup script after the 'export G4INSTALL=...' line and before the 'export LD_LIBRARY_PATH=...' line. I also modified the LD_LIBRARY_PATH line to: export LD_LIBRARY_PATH=${CLHEP_BASE_DIR}/lib:${G4LISTS_BASE}:/usr/local/Inventor/lib:$LD_LIBRARY_PATH. To actually use the setup script you need to run it. (You may have to make it runnable by typing 'chmod u+x setup-geant4.sh'.) To check that the setup script set the environmental variables you can type 'export | grep G4' and 'export | grep LD' (env | grep G4 and env | grep LD in csh and tcsh). If you do this you should see something like the following:
    declare -x G4HERE="/usr/local"
    declare -x G4INSTALL="/usr/local/geant4.6.2.p01"
    declare -x G4LISTS_BASE="/usr/local/geant4.6.2.p01/hadronic_lists"
    declare -x G4SYSTEM="Linux-g++"
    
    and
    
    declare -x LD_LIBRARY_PATH="/usr/local/CLHEP/lib:/usr/local/geant4.6.2.p01/hadronic_lists:/usr/local/Inventor/lib:"
    declare -x OLDPWD="/usr/local/geant4.6.2.p01/hadronic_lists"
    
    Note: running the setup script and then modify and rerunning it, will not set the new, modified environmental variables. The old environmental variables will remain. The old environmental variables can be cleared by closing the xterm in which the setup script was run, and the new environmental variables can be set by running the setup script in a new xterm.
  • Setup the CLHEP libraries by creating a CLHEP directory in the /usr/local directory, copying the downloaded CLHEP file, clhep-1.8.1.0-gcc-3.2.tar.gz, to the new CLHEP directory, and gunzipping and untarring it.
  • Prepare to setup the geant4 source files by copying the source files, geant4.6.2.p01.tar.gz, to /usr/local and gunzipping and untarring them.
  • The data files need to reside in a data directory in the geant4.6.2.p01 directory. Enter the geant4.6.2.p01 directory and type 'mkdir data' to create the data directory. Copy the 5 data files to the newly created data directory and gunzip and untar them.
  • There is a bug in $G4INSTALL/source/processes/hadronic/models/cascade/cascade/src/G4CascadeInterface.cc file that can cause geant4 to segmentation fault. This bug will be fixed when the next patch is released. The following two lines at the end of this file must be commented out:
    if(cascadeParticle != NULL) delete cascadeParticle;
    if(aFragment != NULL) delete aFragment;
    
    These two lines are lines number 391 and 392 in my copy of the source code.
  • To compile the source directory, type make in the $G4INSTALL/source directory. (This step took about an hour or so on my machine.) Compiling of the source directory can be UNdone by typing 'make clean' in the source directory.
  • Since I walked away (ok, I took a quick peek at the baseball game) while the source code was compiling, I need a quick way to check for errors that occurred. Retyping make in the source directory is an effective way of doing this, directories of source code that already compiled correctly will simply echo "make[2]: Nothing to be done for `lib'." to the screen.
  • The Makefile in the visualization directory does not attempt to compile the OpenGL and the OpenInventor directories. Typing make in the OpenGL directory quickly compiles OpenGL source code, however typing make in the OpenInventor directory yields a large number of errors. The first error reads
    'src/SoTubs.cc:36:28: Inventor/SbBox.h: No such file or directory'.
    This is because the include/Inventor directory is missing. The missing directory can be restored by pointing the browser OpenInventor's download page and downloading the sgi-OpenInventor-devel-2.1.5-10.i386.tar.gz file. After gunzipping and untarring the downloaded file in a temporary location, the usr/include/Inventor directory should be copied to $G4INSTALL/source/visualization/OpenInventor/include. Now typing make in the OpenInventor directory will work.
  • The OpenInventor library files need to be put in a directory that is listed in the LD_LIBRARY_PATH. This is the reason for '/usr/local/Inventor/lib' to be included in the LD_LIBRARY_PATH. If the Inventor directory does not exist in /usr/local, create it by typing 'mkdir /usr/local/Inventor'. In the last step, sgi-OpenInventor-devel-2.1.5-10.i386.tar.gz was gunzipped and untarred to a temporary directory. Copy the usr/lib directory that is located inside the temporary directory to /usr/local/Inventor by typing 'cp temp_dir_location/usr/lib/ /usr/local/Inventor/ -r'.
  • Type make in the $G4INSTALL/hardronic_lists/lists directory to compile the various hadronic file lists. (This only took a few minutes on my machine.) Compiling of the lists directory can be UNdone by typing 'make clean' in the source directory.
  • To create the overall library files, cd $G4INSTALL and type ./Configure -install. A series of questions regarding the details of the desired installation will be presented. By default, some of the default answers well be wrong. For example, the default installation directory for the geant4 installation is /root/geant4 while in this example the installation directory was /usr/local/geant4.6.2.p01. Note: the Configure script does not work perfectly. For example, setting the debug mode to 'y' did not enable the debug mode. (See below for how to change the Configure script's default answers.) Below are the installation settings that worked for me:
    [root@cdms geant4.6.2.p01]# ./Configure -install
     
     
     
                    --- Geant4 Toolkit Installation  ---
     
     
     
     
     
    This installation shell script will examine your system and ask you questions
    to determine how the Geant4 Toolkit should be installed.  If you get stuck on
    a question, you may use a ! shell escape to start a subshell or execute a
    command.  Many of the questions will have default answers in square brackets;
    typing carriage return will set the default.
    
    On AFS it is allowed to specify either absolute or relative
    paths (i.e. starting with the ~username construct).
    [Type carriage return to continue] 
    
    The prompt used in this script allows you to use shell variables and backticks
    in your answers. You may use $1, $2, etc...  to refer to the words in the
    default answer, as if the default line was a set of arguments given to a
    script shell. This means you may also use $* to repeat the whole default line.
    
    Everytime there is a substitution, you will have to confirm.  If there is an
    error (e.g. an unmatched backtick), the default answer will remain unchanged
    and you will be prompted again.
    
    Running 'Configure -d' will bypass nearly all the questions and
    use the computed defaults (or answers saved in a configuration
    previously generated).
    
    Type 'Configure -h' for a list of options.
    
    You may also start interactively and then answer '& -d' at any prompt to turn
    on the non-interactive behaviour for the rest of the execution.
    
    [Type carriage return to continue] 
    
    Much effort has been spent to ensure that this shell script will run on any
    Unix system. If despite that you can't run Configure for some reason, you'll
    have to set the proper environment variables by hand and follow the "manual"
    installation as specified in the Geant4 Installation Guide.
    
    [Type carriage return to continue] 
    
    Definition of G4SYSTEM variable is Linux-g++.
    That stands for:
    
    1) OS           : Linux
    
    2) Compiler     : g++
    
    To modify default settings, select number above (e.g. 2) 
    [Press [Enter] for default settings] 
     
    I can set things up so that your shell scripts and binaries are more portable,
    at what may be a noticable cost in performance.  In particular, if you
    ask to be portable, the following happens:
    
         1) Shell scripts will rely on the PATH variable rather than using
            the paths derived above.
         2) ~username interpretations will be done at run time rather than
            by Configure.
    
    Do you expect to run these scripts and binaries on multiple machines? [n] 
     
    Where is Geant4 installed?  [/root/geant4] /usr/local/geant4.6.2.p01
    
    Do you want to copy all Geant4 headers 
    in one directory? [n] 
     
    
    (OPTIONAL) You can now customise installation directories:
      G4TMP - tmp/ containing temporary dependency (.d) and object (.o) files;
      G4LIB - lib/ containing final static (.a) or shared (.so) libraries;
    
    1) G4TMP:               /usr/local/geant4.6.2.p01/tmp
    
    2) G4LIB:               /usr/local/geant4.6.2.p01/lib
    
    To modify default settings, select number above (e.g. 2) 
    [Press [Enter] for default settings] 
     
    
    Please, specify directories where the Geant4 data is installed:
    
    1) G4LEVELGAMMADATA:            /usr/local/geant4.6.2.p01/data/PhotonEvaporation
    
    2) G4RADIOACTIVEDATA:           /usr/local/geant4.6.2.p01/data/RadiativeDecay
    
    3) G4LEDATA:                    /usr/local/geant4.6.2.p01/data/G4EMLOW2.3
    
    4) NeutronHPCrossSections:      /usr/local/geant4.6.2.p01/data/G4NDL3.7
    
    5) G4ELASTICDATA:               /usr/local/geant4.6.2.p01/data/Elastic
    
    To modify default settings, select number above (e.g. 2) 
    [Press [Enter] for default settings] 
    
    Could not find CLHEP installed on this system!
    Please, specify where CLHEP is installed (set by default):
    
    CLHEP_BASE_DIR:                 /usr/local
    
    According to it will be set:
    
    CLHEP_INCLUDE_DIR
    CLHEP_LIB_DIR
    CLHEP_LIB
    
    You will be asked about customizing these next. 
    [/usr/local] /usr/local/CLHEP
    
    You can customize paths of you CLHEP installation:
    
    1) CLHEP_INCLUDE_DIR:           /usr/local/CLHEP/include
    2) CLHEP_LIB_DIR:               /usr/local/CLHEP/lib
    3) CLHEP_LIB:                   CLHEP
    
    To modify default settings, select number above (e.g. 2) 
    [Press [Enter] for default settings] 
     
     
     
     
    
    
    By default 'static' (.a) libraries are built.
    
    Do you want to build 'shared' (.so) libraries?
    [n] y
    
    
    You selected to build 'shared' (.so) libraries. 
    Do you want to build 'static' (.a) libraries too?
    [n] y
     
     
     
    
    
    Do you want to build 'global' compound libraries? [n] 
     
    
    
    Do you want to compile libraries in DEBUG mode (-g)? [n] 
     
    
     
    
    
      G4UI_NONE
    
    If this variable is set, no UI sessions nor any UI libraries are built. 
    This can be useful when running a pure batch job or in a user framework 
    having its own UI system.
    Do you want to set this variable ?
    [n] 
    
      G4UI_BUILD_XAW_SESSION
      G4UI_USE_XAW
    
      Specifies to include and use the XAW interfaces in the
      application to be built.
      The XAW (X11 Athena Widget set) extensions are required to activate 
      and build this driver.
    [n] y
    
      G4UI_BUILD_XM_SESSION
      G4UI_USE_XM
    
      Specifies to include and use the XM Motif based user interfaces.
      The XM Motif extensions are required to activate and build this
      driver.
    [n] y
     
    
    
      G4VIS_NONE
    
    If this variable is set, no visualization drivers will be built or used.
    Do you want to set this variable ?
    [n] 
    
      G4VIS_BUILD_OPENGLX_DRIVER
      G4VIS_USE_OPENGLX
    
    It is an interface to the de facto standard 3D graphics library,
    OpenGL. It is well suited for real-time fast visualization
    and prototyping. The X11 version of the OpenGL libraries is
    required.
    [n] y
    
      G4VIS_BUILD_OPENGLXM_DRIVER
      G4VIS_USE_OPENGLXM
    
    It is an interface to the de facto standard 3D graphics library,
    OpenGL. It is well suited for real-time fast visualization
    and prototyping. The X11 version of the OpenGL libraries and 
    the Motif Xm extension is required.
    [n] y
    
      G4VIS_BUILD_DAWN_DRIVER
      G4VIS_USE_DAWN
    
    DAWN drivers are interfaces to the Fukui Renderer DAWN. DAWN is
    a vectorized 3D PostScript processor suited to prepare technical
    high quality outputs for presentation and/or documentation.
    [n] y
    
      G4VIS_BUILD_OIX_DRIVER
      G4VIS_USE_OIX
    
    This driver is based on the "Hepvis" class library.
    The OpenInventor driver and the Hepvis class library are based
    on OpenInventor technology for scientific visualization.
    The X11 version of OpenInventor is required.
    [n] y
    
      G4VIS_BUILD_VRML_DRIVER
      G4VIS_USE_VRML
    
    These driver generate VRML files, which describe 3D scenes to be 
    visualized with a proper VRML viewer.
    [n] y
    
      OGLHOME/include
      OGLHOME/lib
    
    You have selected to use OpenGL driver.
    Specify the correct path (OGLHOME) where OpenGL is installed in your system.
    It was found in: 
    [/usr] 
     
    
    
      G4LIB_BUILD_G3TOG4  
    
    If this variable is set, it will be built G3TOG4 module.
    Do you want to set this variable ?
    [n] 
     
    
    
      G4ANALYSIS_USE
    
    Activates the configuration setup for allowing plugins to
    analysis tools based on AIDA (Astract Interfaces for Data
    Analysis). In order to use AIDA features and compliant analysis
    tools, the proper environment for these tools will have to be
    set (see documentation for the specific analysis tools).
    [n] y
     
    End of configuration phase.
     
     
    Creating configuration setup file...
    
    WARNING: the generated configuration file
    can be edited if necessary!
    You can introduce any change to the configuration file
    /usr/local/geant4.6.2.p01/.config/bin/Linux-g++/config.sh before the final installation. 
    To do so, use a shell escape now (e.g. !vi /usr/local/geant4.6.2.p01/.config/bin/Linux-g++/conf
    ig.sh).
    
    Press [Enter] to start installation or use a shell escape to edit config.sh: 
    
    Once the creation of all the library is completed, the ./Configure -install should complete with a message similar to the following:
    ####################################################
    # Your Geant4 installation seems to be successful!  
    # To be sure please have a look into the log file:  
    # /usr/local/geant4.6.2.p01/.config/bin/Linux-g++/g4make.log                              
    ####################################################
    
    As far as I can tell, no './Configure clean' option that remove the library files that were created by the './Configure -install' command exists. The newly created library can be removed by typing 'rm -f *' in the $G4INSTALL/lib/$G4SYSTEM directory. If one attempts to recreate the overall library files by typing ./Configure -install again SOME of the default answers will have changed to the ones that were last entered. The default answers are set in the $G4INSTALL/.config/bin/$G4SYSTEM/config.sh file. Note: the setting the debug mode to 'y' when using the ./Configure -install command did NOT set the debug mode to true. To set the debug mode to true, I had to modify the the default debug mode answer in the $G4INSTALL/.config/bin/$G4SYSTEM/config.sh file.



  • Last updated by Joel Sander, joel@hep.ucsb.edu, on 10/12/04.

    Here is a link to a website with some sweet art.