Problem in Installation of Geant4

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

*Geant4 Version:*geant4-v11.3.2
Operating System:Ubuntu 24.04
*Compiler/Version:*gcc 13.3.0
CMake Version:

Sir,

   This thread got closed by mistake.So I could not communicate with you.I have started a new thread.This was my question:
Sir,
I have followed the installation guide to get :abhijit@abhijit:~/Documents/geant4-v11.3.2-build$ cmake -DCMAKE_INSTALL_PREFIX=/path/to/geant4-v11.3.0-install /path/to/geant4-v11.3.0. But running this code is giving error messages with /path/to replaced accordingly.I am not understanding what to write for the path of the install directory and source directory in place of “/path/to” - specially the 2nd “/path/to” which is the path of the source directory. Geant4 is saved in the Documents directory. Do I have to install CMake first?I have not done that yet.
With Regards,
Abhijit
This was your reply:
Yes, you have to install CMake first otherwise the cmake command will not be available. It’s worth checking if it is installed already by running which cmake and see if it prints something like “cmake not found”. If that’s the case you’ll need to install it through apt or similar.

For the /path/to replacements, if you’ve followed the steps in the Installation Guide, then /path/to would be ~/Documents, so there would be directories:

~/Documents/geant4-v11.3.2         (where the Geant4 source code is)
~/Documents/geant4-v11.3.2-build   (where the build will be done)
~/Documents/geant4-v11.3.2-install (where the headers, libraries etc will go)
At the moment it sounds like you only have the ~/Documents/geant4-v11.3.2 directory, and that holds the Geant4 source code? If that’s the case then /path/to is ~/Documents in your case.

I have checked that cmake is installed. Still when I do the requisites according to your prescription I get the following error messages:
abhijit@abhijit:~/Documents/geant4-v11.3.2-build$ cmake -DCMAKE_INSTALL_PREFIX=/Documents/geant4-v11.3.2-install /Documents/geant4-v11.3.2
CMake Error: The source directory "/Documents/geant4-v11.3.2" does not exist.
Specify --help for usage, or press the help button on the CMake GUI. But my Documents directory definitely contains geant4-v11.3.2.I have checked.What to do? 

You’re pointing to /Documents instead of ~/Documents (your home). Use full paths in your home:

mkdir -p ~/Documents/geant4-v11.3.2-build
cd ~/Documents/geant4-v11.3.2-build

cmake -DCMAKE_INSTALL_PREFIX="$HOME/Documents/geant4-v11.3.2-install" \
      "$HOME/Documents/geant4-v11.3.2"

cmake --build . -j$(nproc)
cmake --install .
1 Like

I have installed cmake through your generous help. But now if I want to run exampleB1.cc file which is contained in geant4-v11.3.2/examples/basic/B1 ,what do I do?

Have you installed Geant4 itself already as @dkonst and I showed above? If so, how to build and run B1 is documented in the first chapter of the Application Developer Guide and in particular here: How to Make an Executable Program — Book For Application Developers 11.3 documentation.

Yes sir,

I have totally followed dkonst sir and installed the necessary files. It showed the version of cmake.Does that complete the installation of Geant 4?I am not quite sure about that. Thinking that the installation part is really over, I just had a glimpse of the contents of the links you sent.They were to say the truth quite scary. But I shall stick to them and hopefully understand them, God willing. Hope to get more help from you if any problem arises. With regards,

Abhijit

Sir,

I have gone through the guide Application Developer Guide in a cursory way which is suggestion in execution part to run the command > exampleB1 run1.mac. But this is giving the error message:

>exampleB1 run1.mac
bash: cd: too many arguments

With Regards,

Abhijit

l

Sir,

I have tried this command also: “abhijit@abhijit:~/Documents/geant4-v11.3.2/examples/basic/B1$ exampleB1 run1.mac exampleB1: command not found” without success.Actually since I am new I am getting confused with so many commands at disposal.It would be of immense help if you send the actual command keeping in mind that I am a novice in this field. I think before running I have to compile exampleB1.cc.Where do I find that command.With regards,

Abhijit

Sir,

  Please give me some hint regarding running of files in Geant4 which is easily comprehensible by me.With regards,
Abhijit

Assuming that you have installed Geant4 in $HOME/Documents/geant4-v11.3.2-install and that the Geant4 source code is in $HOME/Documents/geant4-v11.3.2 as outlined previously, then to build example B1, you could do:

cd $HOME/Documents
mkdir exampleB1-build
cd exampleB1-build
cmake -DCMAKE_PREFIX_PATH="$HOME/Documents/geant4-v11.3.2-install" $HOME/Documents/geant4-v11.3.2/examples/basic/B1
make

then to run it:

./exampleB1

or

./exampleB1 run1.mac

Sir,

With my wisdom I have run the commands:abhijit@abhijit:~/Documents/exampleB1-build$ cmake -DCMAKE_PREFIX_PATH=“$HOME/Documents/geant4-v11.3.2-install” $HOME/Documents/geant4-v11.3.2/examples/basic/B1

CMake Error at CMakeLists.txt:11 (find_package):
By not providing “FindGeant4.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “Geant4”, but
CMake did not find one.

Could not find a package configuration file provided by “Geant4” with any

of the following names:

Geant4Config.cmake geant4-config.cmake

Add the installation prefix of “Geant4” to CMAKE_PREFIX_PATH or set

“Geant4_DIR” to a directory containing one of the above files. If “Geant4”
provides a separate development package or SDK, be sure it has been
installed.

– Configuring incomplete, errors occurred!

Thinking that there is some problem with installation of Geant4 in $HOME/Documents/geant4-v11.3.2-install I tried the command : source $HOME/Documents/geant4-v11.3.2-install/share/Geant4-11.3.2/geant4make/geant4make.sh

bash: /home/abhijit/Documents/geant4-v11.3.2-install/share/Geant4-11.3.2/geant4make/geant4make.sh: No such file or directory

searching NET but both without success.I followed **dkonst sir while installing cmake for geant4 initially.**Where am I going wrong?With regards,

Abhijit

O.k., so you’ve installed CMake but you haven’t installed Geant4 itself. Geant4 is C++ code, and requires compilation and installation before you can build an application using it.

The instructions for this were given earlier, i.e. (I’ve added some options to help later use of exampleB1):

cd $HOME/Documents
mkdir geant4-v11.3.2-build
cd geant4-v11.3.2-build
cmake -DCMAKE_INSTALL_PREFIX="$HOME/Documents/geant4-v11.3.2-install" -DGEANT4_INSTALL_DATA=ON "$HOME/Documents/geant4-v11.3.2"
cmake --build . -j$(nproc)
cmake --install .

Now, if you already have a geant4-v11.3.2-build directory, the mkdir command might complain that this directory already exists, but that’s fine, don’t worry about that.

If it all works, then you should check that the $HOME/Documents/geant4-v11.3.2-install directory contains directories named include, lib64, share, and that there’s a file $HOME/Documents/geant4-v11.3.2-install/lib64/cmake/Geant4/Geant4Config.cmake.

Sir,

This is what I get following your prescription verbatim:

abhijit@abhijit:~/Documents/geant4-v11.3.2-install$ ls

CMakeCache.txt CMakeFiles

No such directories/files :include, lib64, share, $HOME/Documents/geant4-v11.3.2-install/lib64/cmake/Geant4/Geant4Config.cmake.

Abhijit

Sir,

Previously I had done some mistake while following your commands but finally when I did it correctly I get: abhijit@abhijit:~/Documents/geant4-v11.3.2-install$ dir bin CMakeCache.txt CMakeFiles include lib share and when I go to run exampleB1 according to your prescription I get: abhijit@abhijit:~/Documents/exampleB1-build$ ./exampleB1 ./exampleB1: error while loading shared libraries: libG4graphics_reps.so: cannot open shared object file: No such file or directory abhijit@abhijit:~/Documents/exampleB1-build$ ./exampleB1 run1.mac ./exampleB1: error while loading shared libraries: libG4graphics_reps.so: cannot open shared object file: No such file or directory .With regards,

Abhijit

For future posts, please read the guide to formatting text and particularly code/commands here: How to post code snippets. A wall of text of commands etc is very hard to understand and thus provide help.

I’m not sure exactly what sequence of commands you’ve used to build exampleB1 as this error is not usually present when building with CMake as we’ve suggested. That said, the cause is due to the executable not finding the libraries, and it should be possible to rectify this by doing:

cd ~/Documents/exampleB1-build

then

source ~/Documents/geant4-v11.3.2-install/bin/geant4.sh

then try running the example again:

./exampleB1
1 Like

Sir,

This time after the latest modification according to your hint it has run. But it is very difficult for me to understand what I have got. Can you give me some more hint about what I have got on running the program in a nutshell. Also the output is stuck up at \idle> and not coming back to the terminal promptly.With regards,

Abhijit

Sir,

I have to use the command:

‘’‘abhijit@abhijit:~/Documents/exampleB1-build$ source ~/Documents/geant4-v11.3.2-install/bin/geant4.sh’‘’ each time I intend to run the following command:
‘’‘abhijit@abhijit:~/Documents/exampleB1-build$ ./exampleB1’‘’
Otherwise it is not working. And when it is running the output is a huge one which I can understand only bits and pieces. It is ending at ‘’’ Idle>‘’’ from where i am not getting the the root directory or whatever very promptly. In fact it is getting stuck up from where I have to close the page i.e. quit it to get back to the linus root directory.With regards,
Abhijit

Sir,
Is the running of exampleB1 with ‘’’ Idle>‘’’ as the last output line where it got stuck ok?
With Regards,
Abhijit

I think nearly all examples include test case macro inputs with “.in” and outputs with that input of “.out”. B1 has one.

1 Like

Sir,
Yes I was about to say the same thing that I have compared my output with exampleB1.out. They are quite similar if not totally same which I am yet to be confirmed about. But the main thing is that it has run with your constant guidance.But only thing that is still bothering me to an extent is that why is the cursor getting stuck on ’’ Idle>‘’’ and not returning to the prompt? Sorry to bother you so many times.With regards,
Abhijit

Sir,
One more question what is the relation between exampleB1.in and exampleB1.out.Because in the first case Energy ~MeV while in the second there is copious presence of TeV.With regards,
Abhijit