How to link Geant4 with a code

Dear All,

I works on detector simulation, for that I have to link Geant4 (already installed in my laptop) with my code/project. For that purpose, I need to export path to Geant4. Can anyone please suggest me - how I can export path to Geant4 (what exactly will be the command for that)?

Many thanks in advance.


Sounds like you want this section of the Installation Guide:

If you’re using plain old Make, then you would source /share/geant4make/ (or .csh) to define lots and lots of envrionment variables, and probably make use of $G4INSTALL/config/binmake.gmk in the Makefile for your application executable. Note that plain old Make is no longer fully supported by the Geant4 developers, so you’re somewhat on your own.

Hi Michael,
Thank you for quick reply and suggestions.
I have installed Geant4 using following commands:

$ cd /path/to/geant4-v11.0.0-build
$ cmake -DCMAKE_INSTALL_PREFIX=/path/to/geant4-v11.0.0-install /path/to/geant4-v11.0.0
$ make -jN
$ make install

My code is in a directory named say “XY” ; so I need to export path to Geant4 - (to link Geant4 to XY) : this is what exactly I have to do?


Hi Michael,

To do the above mentioned: Should I do: Install my “XY” directory (having my code) in Geant4-Install directory? - so that XY directory can be linked to Geant4??
Am I right?

to export path to Geant4 you can use command:
source /path/to/geant4-v11.0.0-install/bin/
before starting your application.

Hello Marek,

Thank you very much for your reply.
But still I have one doubt that I should run this command “source /path/to/geant4-v11.0.0-install/bin/” in my “XY” directory where I will install my code for simulations ??
Am I right??

You can run the source command anywhere you like. It defines a bunch of environment variables in your shell process. You can change directories, and those envvars don’t change or disappear.

You should build and install your application separately from your Geant4 installation. Don’t mix them up. You may want to read some general documents about building with CMake in order to understand clearly how to organize your code.

OK, thank you very much Michael.

if you add the source command to .bashrc, save it and restart terminal, it won’t be required afterwards.

Ok, thank you Deepak