Loading...
Searching...
No Matches
How to build and run an example

All basic and most of extended examples have a similar structure. The main () function is included in exampleXYZ.cc in the example top directory and the example source code is structered in include and src subdirectories. When the example is built, the executable takes the same name as the file with main () function without .cc extension, exampleXYZ.

Then several macros are provided to run the example with various start-up conditions. These macros have usually .mac extension. Besides these macros, there is often a macro exampleXYZ.in (note its different extension) which is used in Geant4 testing and which output, exampleXYZ.out, can be also included in the distribution.

You can find all details about building the examples in the Geant4 Installation Guide , in the section How to Use the Geant4 Toolkit Libraries . Here we recall only the basics.

Compile and link to generate an executable

% cd path_to_exampleXYZ     # go to directory which contains your example
% mkdir exampleXYZ_build
% cd exampleXYZ_build
% cmake -DGeant4_DIR=path_to_Geant4_installation/lib[64]/cmake/Geant4/ ../exampleXYZ
% make -j N exampleXYZ      # "N" is the number of processes 
% make install              # this step is optional              

Execute exampleXYZ in 'batch' mode from macro files

... go to the directory where the example was built/installed
% ./exampleXYZ  xyz.mac

Execute exampleXYZ in 'interactive mode' with visualization

... go to the directory where the example was built/installed
% ./exampleXYZ
....
Idle> type your commands
....
Idle> exit

See also the explicit instructions for building TestEm1 example at How to build and run TestEm1 example page.


Applications | User Support | Publications | Collaboration