Geant4 install
Linux and Cmake are needed for this tutorial to install Geant4. Ubuntu 16.04 and cmake 3.5.1 was used.
The described installation method is suitable for Geant4 version starting from 9.6. The version of cmake depends on a version of Geant4.
How to get Geant4 source code
The official website of Geant4 is now located at http://geant4.web.cern.ch and there you can download last version of Geant4. Installation files are provided as source code in the Source Files section as a tar or zip archive.
You can also install from precompiled sources, it is the section «Pre-compiled Libraries». I advise you to install it from the source, since then the final programs will work faster.
So, let us download the last source file as geant4.10.03.p03.tar.gz
Where to install Geant4
Further, for convenience, a special folder is selected in the home directory where Geant4 will be installed and all files relating to it will be located.
/home/black/geant4/install_path
You can name the directory as you like, but it is better to avoid spaces and if your locale in the system is not UTF-8, then the path should be all from English letters and numbers, otherwise problems may occur due to differences in encoding.
Unzip the archive, by default it is unpacked into a folder geant4.10.03.p03
, the full path to it now is
/home/black/geant4/install_path/geant4.10.03.p03
To install Geant4 create two directories
geant4.10.03-build
geant4.10.03-install
How it is clear from the names, the "build" folder is for compilation and with "install" is for the installation of Geant4.
Configuration of the Geant4 installation
Open the console and go to the folder geant4.10.03-build
cd /home/black/geant4/install_path/geant4.10.03-build
First you need to run cmake and the command with full launch options looks like:
cmake -DCMAKE_INSTALL_PREFIX=../geant4.10.03.p03-install ../geant4.10.03.p03 -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_X11=ON
where -DCMAKE_INSTALL_PREFIX
is a path of installation, ../geant4.10.03.p03
is the directory in which the source code is located. You can put ..
if it is located in the directory above, otherwise it is better to indicate the full path, -DGEANT4_INSTALL_DATA
enables data download during installation. It is turned off by default, but I propose to enable it, let download everything. In another case you can get problem with not not enough data. About 500 MB will be download. -DGEANT4_USE_QT
enables use of QT and -DGEANT4_USE_OPENGL_X11
switchs on the ability to draw using OpenGL in the window if QT does not work. The compilation is configured for Release
by default, it means there is no debugging in Geant4, to configure debugging Debug
look here.
You can just run
cmake -DCMAKE_INSTALL_PREFIX=../geant4.10.03.p03-install ../geant4.10.03.p03
it should be enough to install Geant4.
The output is:
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- 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
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found EXPAT: /usr/lib/x86_64-linux-gnu/libexpat.so (found version "2.1.0")
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - found
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - not found
-- Looking for Q_WS_QWS
-- Looking for Q_WS_QWS - not found
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found
-- Found Qt4: /usr/bin/qmake (found version "4.8.7")
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Configuring download of missing dataset G4NDL (4.5)
-- Configuring download of missing dataset G4EMLOW (6.50)
-- Configuring download of missing dataset PhotonEvaporation (4.3.2)
-- Configuring download of missing dataset RadioactiveDecay (5.1.1)
-- Configuring download of missing dataset G4NEUTRONXS (1.4)
-- Configuring download of missing dataset G4PII (1.3)
-- Configuring download of missing dataset RealSurface (1.0)
-- Configuring download of missing dataset G4SAIDDATA (1.1)
-- Configuring download of missing dataset G4ABLA (3.0)
-- Configuring download of missing dataset G4ENSDFSTATE (2.1)
-- The following Geant4 features are enabled:
GEANT4_BUILD_CXXSTD: Compiling against C++ Standard '11'
GEANT4_USE_SYSTEM_EXPAT: Using system EXPAT library
GEANT4_USE_QT: Build Geant4 with Qt support
GEANT4_USE_OPENGL_X11: Build Geant4 OpenGL driver with X11 support
-- Configuring done
-- Generating done
-- Build files have been written to: /home/black/geant4/install_path/geant4.10.03.p03-build
If there are these lines at the end
-- Configuring done
-- Generating done
-- Build files have been written to:
it means the successful development of cmake and you can start compiling. If there are errors, see the next section.
If you got errors while installing Geant4
However, on a fresh installation of Ubuntu some errors may appear when packages are missing, here are some examples
First error
Not found package EXPAT
CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find EXPAT (missing: EXPAT_LIBRARY EXPAT_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.5/Modules/FindEXPAT.cmake:56 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
cmake/Modules/Geant4OptionalComponents.cmake:102 (find_package)
CMakeLists.txt:75 (include)
The solution is to install the expat package via synaptic or with the command
sudo apt-get install expat
Sometimes it doesn’t work, then try the command:
sudo apt-get install libexpat1-dev
Second error
Some QT files are missing
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
CMake Error at /usr/share/cmake-3.5/Modules/FindQt4.cmake:1326 (message):
Found unsuitable Qt version "" from NOTFOUND, this code requires Qt 4.x
Call Stack (most recent call first):
cmake/Modules/Geant4InterfaceOptions.cmake:117 (find_package)
CMakeLists.txt:80 (include)
The solution is to install QT4
sudo apt-get install qt4-qmake
or
sudo apt-get install qt4-default
Third error
Missing source files or development kit (dev) for QT
CMake Warning at /usr/share/cmake-3.5/Modules/FindQt4.cmake:626 (message):
/usr/bin/qmake reported QT_INSTALL_LIBS as "/usr/lib/x86_64-linux-gnu" but
QtCore could not be found there. Qt is NOT installed correctly for the
target build environment.
Call Stack (most recent call first):
cmake/Modules/Geant4InterfaceOptions.cmake:117 (find_package)
CMakeLists.txt:80 (include)
Solution
sudo apt-get install libqt4-dev
Fourth error
Missing development files for X11
CMake Error at cmake/Modules/Geant4InterfaceOptions.cmake:225 (message):
could not find X11 Xmu library and/or headers
Call Stack (most recent call first):
CMakeLists.txt:80 (include)
Solution
sudo apt-get install libx11-dev
On fresh installation of Ubuntu 18.04 LTS it required to install a more packages:
sudo apt-get install libx11-dev libxmu-dev
On fresh Ubuntu installation it wasn't more error. It was checked on Ubuntu 18.04 LTS in June 2018.
Compilation and installation of Geant4
After successfully executing cmake, compile the command
make
To make the process faster, compilation can be carried out on several processor cores. I have 4 threads and compile with the command
make -j4
Install after compilation with command
make install
Congratulations, Geant4 is installed!
For a more complete guide in English lock a link http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/installguide.html
In order to use this particular Geant4 installation, set the paths in the console where you will build and execute the project of Geant4 with the command:
source /home/black/geant4/install_path/geant4.10.03-install/bin/geant4.sh
More briefly, you need to specify the path to the file geant4.sh
in the installation directory
source path-to-geant4-install/bin/geant4.sh
You can read about running the example. here.
Good luck!