This section is dedicated to illustrate and justify some of the options used and fixed by default in the compilation of the Geant4 toolkit. It is also meant to be a simple guide for the user/installer to avoid or overcome problems which may occur on some compilers. Solutions proposed here are based on the experience gained while porting the Geant4 code to different architectures/compilers and are specific to the OS's and compiler's version valid at the current time of writing of this manual.
It's well known that each compiler adopts its own internal techniques to produce the object code, which in the end might be more or less perfomant and more or less optimised, depending on several factors also related to the system architecture which it applies to. A peculiarity of C++ compilers nowadays is the way templated instances are treated during the compilation/linkage process. Some C++ compilers need to store temporarily template instantiation files (object files or temporary source code files) in a "template repository" or directory that can be specified as unique or not directly from the compilation command (probably historically coming from the old cfront-based implementation of the C++ compiler).
After the installation of the libraries, we strongly suggest to always distinguish between the installation directory (identified by $G4INSTALL) and the working directory (identified by $G4WORKDIR), in order not to alter the installation area for the template repository.
In Geant4, the path to the template repository (for those
compilers which make use of it) is specified by the environment
variable $G4TREP, which is fixed and points by default to
$G4SYSTEM identifies the system-architecture/compiler
currently used and
$G4WORKDIR is the path to the user
working directory for Geant4.
A secondary template repository
created by default and can be used when building executables to
isolate the main repository used for building the libraries in case
of clashes provoked by conflicting class-names. This secondary
template repository can be activated by defining in the environment
(or in the GNUmakefile related to the test/example to be built) the
G4EXEC_BUILD; once activated, the secondary
repository will become the read/write one, while the primary
repository will be considered read-only.
At the current time, only few compilers still make use of a
template repository. A good recommendation valid in general such
compilers is to make use of a single template repository (specified
$G4TREP environment variable) for building all
Geant4 libraries; then use a secondary template repository
$G4TREP/exec, together with the
$G4EXEC_BUILD flag) when building any kind of example or
It's always good practise to clean-up the secondary template repository from time to time.
The default optimisation level is
Since version 5.0 of the compiler, native-STL is supported and ISO/ANSI compliance is required.
Strict ISO/ANSI compilation is forced (
compiler flags), also code is compiled with high verbosity
-Wall flag). The default optimisation level
Additional compilation options (
-mfpmath=sse) to adopt Pentium4 chip specific floating-point
operations on the SSE unit, can be activated by uncommenting the
relevant part in the
Linux-g++.gmk configuration script.
By doing so, it has been verified a greater stability of results,
making possible reproducibility of exact outputs between debug,
non-optimised and optimised runs. A little performance improvement
(in the order of 2%) can also be achieved in some cases. To be
considered that binaries built using these chip-specific options
will NOT be portable cross platforms; generated applications will
only run on Pentium4-based architectures.
Since version .NET 7.0 of the compiler, ISO/ANSI compliance is required.
The setup adopted for the
g++ compiler on MacOS
resembles in great part the one for Linux systems.
The default optimisation level in this case is
Dynamic libraries (
.dylib) are supported as well; once
built, in order to run the generated application, the user must
specify the absolute path in the system where they're installed
DYLD_LIBRARY_PATH system variable.