Update Win11 Installation authored by Igor Semeniouk's avatar Igor Semeniouk
# Geant4 Installation on Windows 11
[[_TOC_]]
Hire the instructions for native Geant4 installation with the Visual Studio C++ compiler on Windows.
## Windows Requirements
* A 64-bit Intel CPU
* Windows 10 or 11
* Microsoft Visual Studio C++ compiler
The installation tested with Windows 11 MSVC 2022 (v17.9)
## Development Environment
### Installing MSVC in Windows
The Visual Studio can be downloaded from Microsoft
https://visualstudio.microsoft.com/vs/
Community edition 2022 free for individuals and academic users.
The components:
- Visual Core editor
- Desktop development with C++
was necessarily to compile Geant4.
### CMake for Windows
The Visual Studio come with cmake program but without CMake GUI.
We use this cmake for compilation and installing Geant4.
You can download and install latest version directly from
https://cmake.org/download/ or use package installers like
[Scoop](https://scoop.sh) or
[Chocolatey](https://chocolatey.org/install)
### Installing Git
Git for Windows installer can be downloaded directly from Git site
https://git-scm.com/download/win
Step by step installation instruction can be found f.e.
https://phoenixnap.com/kb/how-to-install-git-windows
In _"Adjusting you PATH environments"_ section you need
select "Git from command line and also from 3rd-party software".
You can also use installers, i use git-with-openssh installed with scoop.
## Additional Libraries
In this setup Qt5 installed with help of qt unified online installer,
Other additional libraries was compiled locally from sources.
### Installing Qt
You can get qt installer from https://www.qt.io/download ( you will need
account ).
At time of writing only Qt5 was supported. Geant4 can't be build with Qt6.
On windows you need install latest version of Qt5 (5.15.2) for MSVC 2019 64 bit
and optionally Qt3D additional library.
### Installing Xerces-C
You can download source tar ball or zip from
https://xerces.apache.org/xerces-c/download.cgi
and then follow Build instruction from this site:
https://xerces.apache.org/xerces-c/build-3.html
For compilation you can use _x64 Native Tools Command Prompt_ provided by
Visual Studio.
I use following commands:
```
7z x xerces-c-3.2.5.zip
mkdir xerces-c-build
cd xerces-c-build
cmake -DCMAKE_INSTALL_PREFIX=D:\Xerces-C ..\xerces-c-3.2.5
cmake --build . --config RelWithDebInfo --parallel
ctest -V -C RelWithDebInfo -j 4
cmake --build . --config RelWithDebInfo --parallel --target install
```
The Xerces-C configuration summary like like this:
```
-- Could NOT find Java (missing: Java_JAVA_EXECUTABLE Runtime)
--
-- Xerces-C++ configuration summary
-- --------------------------------
--
-- Version: 3.2.5
-- Library interface version: 3.2
--
-- Installation directory: D:/Xerces-C
-- C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe
-- C++ compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe
--
-- Build shared libraries: ON
-- Path delimiters: "/\"
-- File Manager: windows
-- Mutex Manager: standard
-- Transcoder: windows
-- NetAccessor: winsock
-- Message Loader: inmemory
-- XMLCh type: char16_t
-- Configuring done (191.7s)
-- Generating done (1.5s)
-- Build files have been written to: D:/workspace/installg4/install/MSVC/xerces-c-build
```
### Installing FreeType2
<!--
Windows DLLs of FreeType compiled with Visual Studio can also be downloaded directly from a github repository:
https://github.com/ubawurinna/freetype-windows-binaries
(Not tested)
-->
TODO
## Installing Geant4 and Root on Windows
### Installing Root
Download desired root version from http://root.cern.ch:
```
curl -SLO https://root.cern/download/root_v6.30.04.win64.vc17.zip
```
i download zip, but you can use installer version.
To unpack you mast have zip or 7zip packages installed, using 7zip :
```
cd /d D:\
7z x <path_to_zip>\root_v6.30.04.win64.vc17.zip
```
This will install 64 bit root version 6.28/02 to D:\root directory. But you can use any directory which you prefer. ROOT is installed in _relocatable_ mode.
To use ROOT, you must set its environment sourcing the *thisroot.bat* script from
the ROOT installation directory:
`call D:\root\bin\thisroot.bat`
Visit http://root.cern.ch for more information about ROOT.
### Installing Geant4
You can download geant v11.2.1 installer ( or .zip file ) for Windows 10 , 64 bit compiled using Visual Studio 2022 from geant4 download page:
https://geant4.web.cern.ch/support/download
### Build Geant4 locally
Please, follow Geant4 "Installation Guide" to build geant4
https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/index.html
in project install/MSVS subdirectory you can found build-geant4.bat with command i use to build geant4. The option -DGEANT4_BUILD_MULTITHREADED=ON default for geant4 v11.
You need setup compiler ant qt5 environment before build geant4.
You can use script *setup_env.bat* from `setup\MSVC` to setup compiler and qt in DOS Prompt.
```
git clone ssh://git@gitlab.cern.ch:7999/geant4/geant4.git
cd geant4
git checkout v11.2.1
mkdir g11.2.1-build
cd ..\g11.2.1-build
cmake -DCMAKE_PREFIX_PATH=D:\Xerces-C ^
-DCMAKE_INSTALL_PREFIX=D:\Geant4\11.2.1 ^
-DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_WIN32=ON ^
-DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON ..\geant4
cmake --build . --config RelWithDebInfo --target install --parallel 6
```
## Testing Installation
### 1. Open new DOS Prompt window
- You can use "x86 Native Tools Command Prompt for VS 2022" and setup Qt
environment via command `call <QT_INSTALL_DIR\msvc2019_64\bin\qtenv2.bat`
### 2. Setup environment
The script *setup_env.bat* in scripts subdirectory allow do
setup for compiler and Qt5 in dos prompt, usage:
`call setup_env.bat`
### 3. Test Geant4 installation
Setup Geant4 environment:
```
call d:\Geant4\dev\bin\geant4.bat
```
Try to compile B1 example
```
mkdir B1-Build
cd B1-Build
cmake d:\Geant4\dev\share\Geant4\examples\basic\B1
```
You will see the output like this:
```
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- The C compiler identification is MSVC 19.39.33519.0
-- The CXX compiler identification is MSVC 19.39.33519.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Found XercesC: D:/Xerces-C/lib/xerces-c_3.lib (found suitable version "3.2.5", minimum required is "3.2.5")
-- Found OpenGL: opengl32
-- Found Geant4: D:/Geant4/11.2.1/lib/cmake/Geant4/Geant4Config.cmake (found version "11.2.1")
-- Configuring done (11.6s)
-- Generating done (0.3s)
-- Build files have been written to: D:/workspace/installg4/install/MSVC/B1-Build
```
Now we can build and run example.
The build step:
```cmake --build . --config RelWithDebInfo --parallel 8```
To run example use command:
```RelWithDebInfo\exampleB1.exe run1.mac```
You will see the output like below:
```
**************************************************************
Geant4 version Name: geant4-11-02-patch-01 [MT] (16-February-2024)
<< in Multi-threaded mode >>
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/
**************************************************************
...
<snip>
...
================== Deleting memory pools ===================
Pool ID 'class G4NavigationLevelRep', size : 0.00288 MB
Pool ID 'class G4ReferenceCountedHandle<void>', size : 0.000961 MB
Pool ID 'class G4DynamicParticle', size : 0.000961 MB
Pool ID 'class G4SmartVoxelNode', size : 0.000961 MB
Pool ID 'class G4SmartVoxelProxy', size : 0.000961 MB
Pool ID 'class G4CountedObject<void>', size : 0.000961 MB
Number of memory pools allocated: 6; of which, static: 0
Dynamic pools deleted: 6 / Total memory freed: 0.0077 MB
============================================================
G4Allocator objects are deleted.
UImanager deleted.
StateManager deleted.
RunManagerKernel is deleted. Good bye :)
RunManager is deleted.
```
Check you have no crash and errors in aoutput.
The run program without parameter will open graphics interface.
Visit Geant4 installation Guide for more info:
http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/
### 4. Test ROOT Installation
Example of root v6.30/04.
Setup root environment if not yet done:
```
workspace> call d:\root\bin\thisroot.bat
```
Start the ROOT interactive session:
```
D:\workspace>root
------------------------------------------------------------------
| Welcome to ROOT 6.30/04 https://root.cern |
| (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for win64 on Jan 31 2024, 09:17:16 |
| From heads/master@tags/v6-30-04 |
| With MSVC 19.32.31332.0 |
| Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
root [0]
```
and type `.demo` after the ROOT prompt:
```
root [0] .demo
```
You will see the ROOT demo bar and can run some demos by clicking on the demo menu.
You need to go from up to down in the menu, some demos depend on the previous demos results.
To quit ROOT type .q on the ROOT prompt
```
root [1] .q
Taking a break from ROOT? Hope to see you back!
>
```
## Tips ##
- Geant4
- You check the Geant4 datasets installation using the command:
`geant4-config --check-datasets`
- `geant4-config --help` also shows the Geant4 features (configuration options)
You can use geant4-config from `git-bash` prompt, to do so just start git-bash
from dos prompt windows where you already setup development environment for geant4. You also can use `git-bash` to execute `SetupForDevelopment.sh` script.
With help of *gent4-config.bat* wrapper you can execute gent4-config directly
from DOS prompt, as gent4-config is a posix shell script you need have
sh.exe and several other unix utilities to make it work. The two possible
solution was tested.
- use unix utilities from git installation. You will need add directory
`<git_install_die>\usr\bin` to you dos path
- use busybox installed with his aliases, i use `scoop install busybox`
to install the busybox.
# Geant4 Installation on Windows 11
<!--
For Geant4 version 11.2.0 you can also apply pathch win.path
which you can found in installg4/install/MSVC/ directory.
-->
[[_TOC_]]
Hire the instructions for native Geant4 installation with the Visual Studio C++ compiler on Windows.
## Windows Requirements
* A 64-bit Intel CPU
* Windows 10 or 11
* Microsoft Visual Studio C++ compiler
The installation tested with Windows 11 MSVC 2022 (v17.13.5) and Qt 5.12.2
## Development Environment
### Installing MSVC in Windows
The Visual Studio can be downloaded from Microsoft
https://visualstudio.microsoft.com/vs/
Community edition 2022 free for individuals and academic users.
The components:
- Visual Core editor
- Desktop development with C++
was necessarily to compile Geant4.
### CMake for Windows
The Visual Studio come with cmake program but without CMake GUI.
We use this cmake for compilation and installing Geant4.
You can download and install latest version directly from
https://cmake.org/download/ or use package installers like
[Scoop](https://scoop.sh) or
[Chocolatey](https://chocolatey.org/install)
### Installing Git
Git for Windows installer can be downloaded directly from Git site
https://git-scm.com/download/win
Step by step installation instruction can be found f.e.
https://phoenixnap.com/kb/how-to-install-git-windows
In _"Adjusting you PATH environments"_ section you need
select "Git from command line and also from 3rd-party software".
You can also use installers, i use git-with-openssh installed with scoop.
## Additional Libraries
In this setup Qt5 installed with help of qt unified online installer,
Other additional libraries was compiled locally from sources.
### Installing Qt
You can get qt installer from https://www.qt.io/download ( you will need
account ).
At time of writing only Qt5 was supported. Geant4 can't be build with Qt6.
On windows you need install latest version of Qt5 (5.15.2) for MSVC 2019 64 bit
and optionally Qt3D additional library.
### Installing Xerces-C
You can download source tar ball or zip from
https://xerces.apache.org/xerces-c/download.cgi
and then follow Build instruction from this site:
https://xerces.apache.org/xerces-c/build-3.html
For compilation you can use _x64 Native Tools Command Prompt_ provided by
Visual Studio.
I use following commands:
```
7z x xerces-c-3.2.3.zip
mkdir xerces-c-build
cd xerces-c-build
cmake -DCMAKE_INSTALL_PREFIX=D:\Xerces-C ..\xerces-c-3.2.3
cmake --build . --config RelWithDebInfo --parallel
ctest -V -C RelWithDebInfo -j 4
cmake --build . --config RelWithDebInfo --parallel --target install
```
The Xerces-C configuration summary like like this:
```
-- Could NOT find Java (missing: Java_JAVA_EXECUTABLE Runtime)
--
-- Xerces-C++ configuration summary
-- --------------------------------
--
-- Version: 3.2.5
-- Library interface version: 3.2
--
-- Installation directory: D:/Xerces-C
-- C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe
-- C++ compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe
--
-- Build shared libraries: ON
-- Path delimiters: "/\"
-- File Manager: windows
-- Mutex Manager: standard
-- Transcoder: windows
-- NetAccessor: winsock
-- Message Loader: inmemory
-- XMLCh type: char16_t
-- Configuring done (191.7s)
-- Generating done (1.5s)
-- Build files have been written to: D:/workspace/installg4/install/MSVC/xerces-c-build
```
### Installing FreeType2
<!--
Windows DLLs of FreeType compiled with Visual Studio can also be downloaded directly from a github repository:
https://github.com/ubawurinna/freetype-windows-binaries
(Not tested)
-->
TODO
## Installing Geant4 and Root on Windows
### Installing Root
Download desired root version from http://root.cern.ch:
```
curl -SLO https://root.cern/download/root_v6.34.06.win64.python311.vc17.relwithdebinfo.zip
```
i download zip, but you can use installer version.
To unpack you mast have zip or 7zip packages installed, using 7zip :
```
cd /d D:\
7z x <path_to_zip>\root_v6.34.06.win64.python311.vc17.relwithdebinfo.zip
```
This will install 64 bit root version 6.34/06 to D:\root directory. But you can use any directory which you prefer. ROOT is installed in _relocatable_ mode.
To use ROOT, you must set its environment sourcing the *thisroot.bat* script from
the ROOT installation directory:
`call D:\root\bin\thisroot.bat`
Visit http://root.cern.ch for more information about ROOT.
### Installing Geant4
You can download geant v11.3.1 installer ( or .zip file ) for Windows 10 , 64 bit compiled using Visual Studio 2022 from geant4 download page:
https://geant4.web.cern.ch/download/11.3.1.html
### Build Geant4 locally
Please, follow Geant4 "Installation Guide" to build geant4
https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/index.html
in project install/MSVS subdirectory you can found build-geant4.bat with command i use to build geant4. The option -DGEANT4_BUILD_MULTITHREADED=ON default for geant4 v11.
You need setup compiler ant qt5 environment before build geant4.
You can use script *setup_env.bat* from `setup\MSVC` to setup compiler and qt in DOS Prompt.
```
git clone ssh://git@gitlab.cern.ch:7999/geant4/geant4.git
cd geant4
git checkout v11.1.1
mkdir g11.1.1-build
cd ..\g11.1.1-build
cmake -DCMAKE_PREFIX_PATH=D:\Xerces-C ^
-DCMAKE_INSTALL_PREFIX=D:\Geant4\11.1.1 ^
-DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_WIN32=ON ^
-DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON ..\geant4
cmake --build . --config RelWithDebInfo --target install --parallel 6
```
## Testing Installation
### 1. Open new DOS Prompt window
- You can use "x86 Native Tools Command Promt for VS 2022" and setup Qt
environment via command `call <QT_INSTALL_DIR\msvc2019_64\bin\qtenv2.bat`
### 2. Setup environment
The script *setup_env.bat* in scripts subdirectory allow do
setup for compiler and Qt5 in dos prompt, usage:
`call setup_env.bat`
### 3. Test Geant4 installation
Setup Geant4 environment:
```
call d:\Geant4\dev\bin\geant4.bat
```
Try to compile B1 example
```
mkdir B1-Build
cd B1-Build
cmake d:\Geant4\dev\share\Geant4\examples\basic\B1
```
You will see the output like this:
```
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.35.32217.1
-- The CXX compiler identification is MSVC 19.35.32217.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Found XercesC: D:/Xerces-C/lib/xerces-c_3.lib (found suitable version "3.2.3", minimum required is "3.2.3")
-- Found OpenGL: opengl32
-- Found Geant4: D:/Geant4/11.1.1/lib/cmake/Geant4/Geant4Config.cmake (found version "11.1.1")
-- Configuring done
-- Generating done
-- Build files have been written to: D:/workspace/GEANT4/B1-build
```
Now we can build and run example.
The build step:
```cmake --build . --config RelWithDebInfo --parallel 4```
To run exaple use command:
```RelWithDebInfo\exampleB1.exe run1.mac```
You will see the output like below:
```
**************************************************************
Geant4 version Name: geant4-11-01-ref-04 [MT] (30-April-2023)
<< in Multi-threaded mode >>
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/
**************************************************************
...
<snip>
...
================== Deleting memory pools ===================
Pool ID 'class G4NavigationLevelRep', size : 0.00288 MB
Pool ID 'class G4ReferenceCountedHandle<void>', size : 0.000961 MB
Pool ID 'class G4DynamicParticle', size : 0.000961 MB
Pool ID 'class G4SmartVoxelNode', size : 0.000961 MB
Pool ID 'class G4SmartVoxelProxy', size : 0.000961 MB
Pool ID 'class G4CountedObject<void>', size : 0.000961 MB
Number of memory pools allocated: 6; of which, static: 0
Dynamic pools deleted: 6 / Total memory freed: 0.0077 MB
============================================================
G4Allocator objects are deleted.
UImanager deleted.
StateManager deleted.
RunManagerKernel is deleted. Good bye :)
RunManager is deleted.
```
Check you have no crash and errors in aoutput.
The run program without parameter will open graphics interface.
Visit Geant4 installation Guide for more info:
http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/
### 4. Test ROOT Installation
Example of root v6.26/02.
Setup root environment if not yet done:
```
D:\workspace>call d:\root\bin\thisroot.bat
```
Start the ROOT interactive session:
```
D:\workspace>root
------------------------------------------------------------------
| Welcome to ROOT 6.26/02 https://root.cern |
| (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for win64 on Apr 12 2022, 16:28:03 |
| From tags/v6-26-02@v6-26-02 |
| With MSVC 19.31.31104.0 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
root [0]
```
and type `.demo` after the ROOT prompt:
```
root [0] .demo
```
You will see the ROOT demo bar and can run some demos by clicking on the demo menu.
You need to go from up to down in the menu, some demos depend on the previous demos results.
To quit ROOT type .q on the ROOT prompt
```
root [1] .q
Taking a break from ROOT? Hope to see you back!
>
```
## Tips ##
- Geant4
- You check the Geant4 datasets installation using the command:
`geant4-config --check-datasets`
- `geant4-config --help` also shows the Geant4 features (configuration options)
You can use geant4-config from `git-bash` prompt, to do so just start git-bash
from dos prompt windows where you already setup development environment for geant4. You also can use `git-bash` to execute `SetupForDevelopment.sh` script.
With help of *gent4-config.bat* wrapper you can execute gent4-config directly
from DOS prompt, as gent4-config is a posix shell script you need have
sh.exe and several other unix utilities to make it work. The two possible
solution was tested.
- use unix utilities from git installation. You will need add directory
`<git_install_die>\usr\bin` to you dos path
- use busybox installed with his aliases, i use `scoop install busybox`
to install the busybox.
- The md5sum command from busybox not support *--tag* option. To allow
geant4-config --install-datasets work correctly you need to install
openssl for windows f.e. `scoop install openssl`.