B1 example: error running make (missing path for Geant4 header files? E.g.G4VUserDetectorConstruction.hh)

Hello,
I’m getting an error when running make, after successfully run cmake as this:

$cmake -DGeant4_DIR="~/Software/Geant4/geant4-install/lib/Geant4-10.5.1" ~/Documents/Simulations/B1

Compilation error (running make):

    ~/G4examples/B1/B1_build$ make
Scanning dependencies of target exampleB1
[ 12%] Building CXX object CMakeFiles/exampleB1.dir/exampleB1.cc.o
In file included from ~/Documents/Simulations/B1/exampleB1.cc:30:
~/Documents/Simulations/B1/include/B1DetectorConstruction.hh:33:10: fatal error: G4VUserDetectorConstruction.hh: No such file or directory
   33 | #include "G4VUserDetectorConstruction.hh"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/exampleB1.dir/build.make:82: CMakeFiles/exampleB1.dir/exampleB1.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:123: CMakeFiles/exampleB1.dir/all] Error 2
make: *** [Makefile:149: all] Error 2

Do you know what can be the problem?
It seems the compiler does not know the Geant4 header files…

I have run the ~/.bashrc file where I added this lines:
if [ -f ~/Software/Geant4/geant4-install/bin/geant4.sh ]; then
. ~/Software/Geant4/geant4-install/bin/geant4.sh
fi

My software:
Geant4 version: 10.05.p01
OS: Ubuntu 20.4
gcc version 9.3.0

Any tips?

Thank you.
Regards,
João

I’m not at a linux machine at the moment, but I think your issue is the use of ~ and the fact that it might not get expanded as you expect. Try replacing it with the full path, i.e. /home/jsmarcos.

Looks like using $HOME could be another options

Thanks for your reply, php1ic.
Actually I’m using the full path. I just changed for this forum post.
This way, the problem must be other.
Thank you!

Are you sure that cmake did not print any error or warning?
Are you sure that Geant4 installation was successful? Do you have those header files in ~/Software/Geant4/geant4-install/include/Geant4/?
Can you try passing to cmake -DCMAKE_PREFIX_PATH=~/Software/Geant4/geant4-install instead? I believe you should be also able to skip those explicit paths if you sourced geant4.sh file.

Thank you, anna.
I can run the example B1 in its original directory (from Geant4 installation).
Does this give you any useful information? I assumed the Geant4 installation was successful based on this.
When running cmake for the B1 example previously copied to another directory (~/Documents/Simulations/B1), everything goes well [please note that I have changed the src directory in the main post for the real one, because before I just wanted to put any example of possible path].

I have the header files in ~/Software/Geant4/geant4-install/include/geant4.10.05.p01/

I have used -DCMAKE_INSTALL_PREFIX=/home/joao/Software/Geant4/geant4-install for the cmake used in Geant4 makefiles production.

Thank you for your time.

Can you try to build your example with:

cmake -DCMAKE_PREFIX_PATH=~/Software/Geant4/geant4-install  ~/Documents/Simulations/B1
make

Yes, I can.
I did it and I obtained exactly the same error copied in the 1st post.

Can you also run make VERBOSE=1 and post the output here please? Given @anna’s instructions, there shouldn’t be an error with finding includes, and the VERBOSE=1 will print where the build is trying to look for them.

Another thing to check is if the initialisation script is being correctly run. Not sure of the offical way to check it but the following 2 commands should contain geant4 related output.

Output from may machine is also shown

$ echo $LD_LIBRARY_PATH
/usr/local/share/geant4/10.5.1/install/debug/lib:/usr/lib/x86_64-linux-gnu:/usr/local/share/cadmesh/install/lib
$ printenv | grep G4
G4ENSDFSTATEDATA=/usr/local/share/geant4/data/G4ENSDFSTATE2.2
G4PIIDATA=/usr/local/share/geant4/data/G4PII1.3
G4INCLDATA=/usr/local/share/geant4/data/G4INCL1.0
G4LEDATA=/usr/local/share/geant4/data/G4EMLOW7.7
G4PARTICLEXSDATA=/usr/local/share/geant4/data/G4PARTICLEXS1.1
G4NEUTRONHPDATA=/usr/local/share/geant4/data/G4NDL4.5
G4SAIDXSDATA=/usr/local/share/geant4/data/G4SAIDDATA2.0
G4REALSURFACEDATA=/usr/local/share/geant4/data/RealSurface2.1.1
G4ABLADATA=/usr/local/share/geant4/data/G4ABLA3.1
G4LEVELGAMMADATA=/usr/local/share/geant4/data/PhotonEvaporation5.3
G4RADIOACTIVEDATA=/usr/local/share/geant4/data/RadioactiveDecay5.3

bmorgan, thanks for the help.
Here it is:

   $~/Documents/Simulations/B1/B1-build$ make VERBOSE=1
    /usr/local/bin/cmake -S/home/joao/Documents/Simulations/B1 -B/home/joao/Documents/Simulations/B1/B1-build --check-build-system CMakeFiles/Makefile.cmake 0
    /usr/local/bin/cmake -E cmake_progress_start /home/joao/Documents/Simulations/B1/B1-build/CMakeFiles /home/joao/Documents/Simulations/B1/B1-build//CMakeFiles/progress.marks
    make  -f CMakeFiles/Makefile2 all
    make[1]: Entering directory '/home/joao/Documents/Simulations/B1/B1-build'
    make  -f CMakeFiles/exampleB1.dir/build.make CMakeFiles/exampleB1.dir/depend
    make[2]: Entering directory '/home/joao/Documents/Simulations/B1/B1-build'
    cd /home/joao/Documents/Simulations/B1/B1-build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/joao/Documents/Simulations/B1 /home/joao/Documents/Simulations/B1 /home/joao/Documents/Simulations/B1/B1-build /home/joao/Documents/Simulations/B1/B1-build /home/joao/Documents/Simulations/B1/B1-build/CMakeFiles/exampleB1.dir/DependInfo.cmake --color=
    make[2]: Leaving directory '/home/joao/Documents/Simulations/B1/B1-build'
    make  -f CMakeFiles/exampleB1.dir/build.make CMakeFiles/exampleB1.dir/build
    make[2]: Entering directory '/home/joao/Documents/Simulations/B1/B1-build'
    [ 12%] Building CXX object CMakeFiles/exampleB1.dir/exampleB1.cc.o
    /usr/bin/c++ -DG4INTY_USE_QT -DG4INTY_USE_XT -DG4LIB_BUILD_DLL -DG4UI_USE -DG4UI_USE_QT -DG4UI_USE_TCSH -DG4VERBOSE -DG4VIS_USE -DG4VIS_USE_OPENGL -DG4VIS_USE_OPENGLQT -DG4VIS_USE_OPENGLX -DG4_STORE_TRAJECTORY -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -I/home/joao/Software/CLHEP/2.4.1.3/CLHEP-install/lib/CLHEP-2.4.1.3/../../include -I/home/joao/Documents/Simulations/B1/include -isystem /home/joao/Software/Geant4/geant4-install/include/Geant4 -isystem /home/joao/Software/CLHEP/2.4.1.3/CLHEP-install/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt5/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt5/QtOpenGL -W -Wall -pedantic -Wno-non-virtual-dtor -Wno-long-long -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-variadic-macros -Wshadow -pipe -DG4USE_STD11 -std=c++11 -O3 -DNDEBUG -fno-trapping-math -ftree-vectorize -fno-math-errno -fPIC -o CMakeFiles/exampleB1.dir/exampleB1.cc.o -c /home/joao/Documents/Simulations/B1/exampleB1.cc
    In file included from /home/joao/Documents/Simulations/B1/exampleB1.cc:30:
    /home/joao/Documents/Simulations/B1/include/B1DetectorConstruction.hh:33:10: fatal error: G4VUserDetectorConstruction.hh: No such file or directory
       33 | #include "G4VUserDetectorConstruction.hh"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    make[2]: *** [CMakeFiles/exampleB1.dir/build.make:82: CMakeFiles/exampleB1.dir/exampleB1.cc.o] Error 1
    make[2]: Leaving directory '/home/joao/Documents/Simulations/B1/B1-build'
    make[1]: *** [CMakeFiles/Makefile2:123: CMakeFiles/exampleB1.dir/all] Error 2
    make[1]: Leaving directory '/home/joao/Documents/Simulations/B1/B1-build'
    make: *** [Makefile:149: all] Error 2

php1ic, welcome back :slight_smile:
Here it is my output:

$ echo $LD_LIBRARY_PATH
/home/joao/Software/Geant4/geant4-install/lib:/home/joao/Software/CLHEP/2.4.1.3/CLHEP-install//lib/::/home/joao/Software/CLHEP/2.4.1.3/CLHEP-install/lib:/usr/lib/x86_64-linux-gnu

$~/Documents/Simulations/B1/B1-build$ printenv | grep G4
G4ENSDFSTATEDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/G4ENSDFSTATE2.2
G4PIIDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/G4PII1.3
G4INCLDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/G4INCL1.0
G4LEDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/G4EMLOW7.7
G4PARTICLEXSDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/G4PARTICLEXS1.1
G4NEUTRONHPDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/G4NDL4.5
G4SAIDXSDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/G4SAIDDATA2.0
G4REALSURFACEDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/RealSurface2.1.1
G4ABLADATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/G4ABLA3.1
G4LEVELGAMMADATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/PhotonEvaporation5.3
G4RADIOACTIVEDATA=/home/joao/Software/Geant4/geant4-install/share/Geant4-10.5.1/data/RadioactiveDecay5.3

Thanks for the info! Based on this line:

    /usr/bin/c++ -DG4INTY_USE_QT -DG4INTY_USE_XT -DG4LIB_BUILD_DLL -DG4UI_USE -DG4UI_USE_QT -DG4UI_USE_TCSH -DG4VERBOSE -DG4VIS_USE -DG4VIS_USE_OPENGL -DG4VIS_USE_OPENGLQT -DG4VIS_USE_OPENGLX -DG4_STORE_TRAJECTORY -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -I/home/joao/Software/CLHEP/2.4.1.3/CLHEP-install/lib/CLHEP-2.4.1.3/../../include -I/home/joao/Documents/Simulations/B1/include -isystem /home/joao/Software/Geant4/geant4-install/include/Geant4 -isystem /home/joao/Software/CLHEP/2.4.1.3/CLHEP-install/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt5/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt5/QtOpenGL -W -Wall -pedantic -Wno-non-virtual-dtor -Wno-long-long -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-variadic-macros -Wshadow -pipe -DG4USE_STD11 -std=c++11 -O3 -DNDEBUG -fno-trapping-math -ftree-vectorize -fno-math-errno -fPIC -o CMakeFiles/exampleB1.dir/exampleB1.cc.o -c /home/joao/Documents/Simulations/B1/exampleB1.cc

it’s looking for the Geant4 headers in /home/joao/Software/Geant4/geant4-install/include/Geant4. Is G4VUserDetectorConstruction.hh present in that directory, and if so, what permissions does it have?

bmorgan, most probably you are finding the problem.

Lets split my answer in two:

  1. The directory with the header files is not
    /home/joao/Software/Geant4/geant4-install/include/Geant4,
    but
    /home/joao/Software/Geant4/geant4-install/include/geant4.10.05.p01,
    instead.

  2. Permission of the file: -rw-r--r--
    I guess I need executable permission and so: -rwxr-xr-x

Regarding the file directory, should I use a flag in cmake to explicitly point to the directory of the header files? Could you please, tell me how to do it?
Thanks.

O.k., how did you install Geant4, i.e. what arguments did you supply to CMake? include/Geant4 is the default (relative to CMAKE_INSTALL_PREFIX) directory where headers are installed, and that’s where CMake thinks they are (as installed/configured). The presence of include/geant4.10.05.p01 suggests the default was modified at configure time, which isn’t wrong, or post install, which would lead to undefined behaviour. We need to know which so we can see if there’s a bug in the CMake script, or to suggest a suitable correction.

My software:
Geant4 version: 10.05.p01
OS: Ubuntu 20.4
gcc version 9.3.0

Command
$ cmake -DCMAKE_INSTALL_PREFIX=/home/joao/Software/Geant4/geant4-install -DGEANT4_USE_QT=ON -DGEANT4_USE_OPENGL_X11=ON -DGEANT4_INSTALL_DATA=ON-DGEANT4_USE_RAYTRACER_X11=ON -DGEANT4_USE_GDML=ON -DGEANT4_USE_SYSTEM_CLHEP=ON -DCLHEP_INCLUDE_DIR=/home/joao/Software/CLHEP/2.4.1.3/CLHEP-install/include/ -DCLHEP_LIBRARY=/home/joao/Software/CLHEP/2.4.1.3/CLHEP-install/lib/libCLHEP.so -DGEANT4_INSTALL_EXAMPLES=ON /home/joao/Downloads/Geant4/geant4.10.05.p01

Thanks! That’s a perfectly fine install, so I don’t know how the directory for the includes got set/moved to what it is. However, the simple fix is to do:

$ cd /home/joao/Software/Geant4/geant4-install/include
$ mv geant4.10.05.p01 Geant4

and the example should then work.

bmorgan, as you predicted, the compilation went very well and the example B1 is running like a charm.
Thank you so much for your time.
I’m also grateful to anna and php1ic!
Best regards

1 Like