~/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
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.
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.
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.
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:
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.
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.
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
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