Changing example and recompiling

Hi there, I am new to Geant4 and to start getting used to the program I am trying to change some aspects of the example B1, like the geometry at first. The thing is, every time I make a change I have to erase the files in the directoy where I compile the example. Is there a way of implementing the change without doing that?

I use Ubuntu 20.04 and these comands in the terminal:
cmake /usr/local/geant4/10.6.2/share/Geant4-10.6.2/examples/basic/B1
make -j4

Thank you.

  1. You don’t need to repeat the cmake step every time. If you modify the source code, the make command will identify the change automatically (the .o file will be older than its corresponding .cc file) and recompile only your change.

  2. You probably don’t want to be modifying the distribution (/usr/local/geant4/…) directly. I’d suggest copying the example you’re playing with (here B1) to your own personal area, modify it as much as you like, and build it there (the argument to cmake will be your directory, not the main distribution).

When you get to the point of making your own applications from scratch, you’ll be doing that in a personal directory anyway, so (2) above will get you used to that model.

Thank you so much for the reply, it greatly helped.