I have installed Geant4 and Visual Studio 2026. I did not install CMake because apparently CMake is included in Visual Studio 2026.
I have created a new project with Visual Studio 2026, of the kind “Console App Windows C++”.
I replaced the main() code with the code of the example contained in the chapter “Getting started with Geant 4 - Running a simple example - How to define the main() program” of the Book For Application Developers and I copied the #include-statements from the example ahead of the main().
But Visual Studio does not find the included files.
Effectively, I have noticed that the examples provided with Geant4, like B1, have a folder \include, where such files are stored. Do I have to create such a folder by hand and fetch and copy the necessary files therein by hand? I can do it, but it’s clear that I am missing something.
Geant4 Version: 11.4.2
Operating System: Windows 10 Pro
Compiler/Version: Microsoft Visual Studio 2026, Version 18.7.3
CMake Version: The version included in Visual Studio 2026
Dear Andrea,
Could you please post the error message you’re getting?
RohitNathawat,
thank you for your help.
I get the following message (in German, because I am in Germany):
Die Erstellung wurde um 15:12 gestartet...
1>------ Erstellen gestartet: Projekt: ErsterVersuch, Konfiguration: Debug x64 ------
1> ErsterVersuch.cpp
1>C:\Users\Green_2124C\source\repos\ErsterVersuch\ErsterVersuch\ErsterVersuch.cpp(6,10): error C1083: Datei (Include) kann nicht geöffnet werden: "DetectorConstruction.hh": No such file or directory
========== Build: 0 erfolgreich, 1 Fehler, 0 aktuell, 0 übersprungen ==========
========== Erstellen abgeschlossen um 15:12 und dauerte 03,019 Sekunden ==========
In English it means: "File (include) can not be open: “DetectorConstruction.hh”: No such file or directory.
The #include-statements in the example from the Book For Application Developers are effectively the following:
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "ActionInitialization01.hh"
#include "G4RunManagerFactory.hh"
#include "G4UImanager.hh"
Hi Andrea,
The error is expected, and it points to a misunderstanding about what those header files are.
DetectorConstruction.hh, PhysicsList.hh, and ActionInitialization01.hh are not part of Geant4 itself. They are user-written classes — every Geant4 application defines its own detector geometry, physics list, and action initialization, and the book’s main() example simply assumes those three files already exist alongside your .cpp file. The book covers how to write them in other chapters (geometry, physics list, primary generator, etc.). You have two options:
-
Write them yourself, following the rest of the “Application Developers” book (there are dedicated chapters for DetectorConstruction, PhysicsList, and the action classes).
-
Copy them from an existing example like B1 (examples/basic/B1/include/ and .../src/) and adapt them — this is what most people do when starting out, since B1 is essentially a minimal working version of exactly this tutorial.
Either way, those three files need to exist as actual files in your project folder (same folder as your .cpp, or a subfolder that you add to the include path).
Geant4 apps need the toolkit’s include paths, library paths, and preprocessor definitions set up correctly, and that’s exactly what the CMakeLists.txt files in each example do for you. The recommended path is take the entire B1 example folder as your starting template (not just the .cpp), including its CMakeLists.txt.
I would suggest you two things:
- If you are beginner go to example B1 and try to modify it according to your needs for tutorial purpose.
- If you want to do everything from scratch you can folllow this youtube playlist.
cheers
Dear RohitNathawat,
thank you very very much for your help!
Now everything is clear.