Geant4 Version: 11.2.2
Operating System: Ubuntu 24.04 as a virtual machine using virtual box
Compiler/Version: gcc 13.2.0
CMake Version: 3.28.3
I’m currently trying to set up one of the examples but every time I run the cmake . . command, I get this error
VirtualBox:~/software/remake/geant4-exercises/B4d-ex/B4d/build$ cmake ..
CMake Error: The current CMakeCache.txt directory /home/user/software/remake/geant4-exercises/B4d-ex/B4d/CMakeCache.txt is different than the directory /home/user/software/remake/geant4-v11.2.2/examples/basic/B4/B4d where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
I only get this when trying to run cmake in a copy of the example as suggested in all the guides I see. Whenever I run the cmake command in the original directory it works but it only loads for 0.3 seconds and whenever I try to run the make command, I get another error saying
VirtualBox:~/software/remake/geant4-v11.2.2/examples/basic/B4/B4d$ make -j4
GNUmakefile:16: ../../../config/binmake.gmk: No such file or directory
make: *** No rule to make target '../../../config/binmake.gmk'. Stop.
I’m completely lost on how to solve either of these issues, so any help would be appreciated.
There’s an existing CMakeCache.txt file in ~/software/remake/geant4-exercises/B4d-ex/B4d which I guess was there from before the directory was copied. Try deleting that along with any CMakeFiles/ directory that’s also present.
Geant4 still provides a GNUmakefile for each example that uses the deprecated “geant4make” build system. As you’ve run cmake in the source directory for the example, CMake has generated a Makefile in that same directory. Since Linux supplies the GNU implementation of make, running make -j4 in a directory that contains both GNUmakefile and Makefile will result in it picking the GNUmakefile. You can either:
Run as make -f Makefile -j4 to force use of the CMake generated makefile.
With CMake it’s good practice to always have a separate directory in which the build is done. This makes it easier to clean up when things go wrong, and to avoid mixing up source and build artifacts in version control.
Thank you! That solved the issue, and I was able to run the example. However, now I’m having the issue of the geometry not loading properly. I looked through everything in the terminal from when it was loading, and I didn’t find any error messages.