Tips for Program Compilation
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.
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.
Unix/Linux - g++
OS: Linux
Compiler: GNU/gcc
Strict ISO/ANSI compilation is forced (-ansi -pedantic
compiler flags), also code is compiled with high verbosity
diagnostics (-Wall flag). The default optimisation level
is -O2. The flag G4OPTDEBUG, if set
in the environment, allows for optimised build of the libraries but
including debug symbols (-O -g compilation option).
Note
Additional compilation options (-march=XXX
-mfpmath=sseYYY) to adopt chip specific floating-point
operations on the SSE unit, can be activated by adapting the
XXX, YYY options and 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 likely NOT be portable cross platforms; generated applications
will only run on the specific chip-based architectures.
Windows - MS Visual C++
OS: MS/Windows
Compiler: MS-VC++
Since version .NET 7.0 of the compiler, ISO/ANSI compliance is
required.
See of the Installation Guide for
more detailed information.
See also for more tips.
MacOS-X - g++
OS: MacOS/Darwin
Compiler: GNU/gcc
The setup adopted for the g++ compiler on MacOS
resembles in most parts the one for Linux systems.
The default optimisation level in this case is -O2.
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
with the DYLD_LIBRARY_PATH system variable.