Installation Prefix issue related to CMake

Ubuntu 22.04
GCC 11.4.0
cmake version 3.29.0

Having error with cmake not being able to identify some files

CMake Error at B1/CMakeLists.txt:15 (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:


  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

Hi Lakshya:

As is shown in this error report, you need to specify the location of Geant4Config.cmake file whenever you use cmake to compile any Geant4 file.

The default location of Geant4Config.cmake is

${your Geant4 installation path}/lib/cmake/Geant4

If you can find Geant4Config.cmake in this path, add

-DGeant4_DIR=${your Geant4 installation path}/lib/cmake/Geant4

when using cmake.

For example, if you want to compile B1 example in B1/build path, you should use

cmake -DGeant4_DIR=${your Geant4 installation path}/lib/cmake/Geant4 ..

I also suggest add the following line to your .bashrc so that you can use g4cmake to compile Geant4 project instead of typing the long cmake command mentioned above.

alias g4cmake='cmake -DGeant4_DIR=${your Geant4 installation path}/lib/cmake/Geant4'

You can also find this solution to your problem in the official Geant4 installation guide: How to Use the Geant4 Toolkit Libraries — Geant4 Installation Guide 11.2 documentation

geant4 has configuration file.
Before tried cmake configuration which any example or you own geant4 application you need
sources ${your Geant4 installation path}/bin/
or geant4.csh depending on shell you are using.

This must be done ones when you open new terminal or tab.

Hi, Thanks you for the reply I followed your steps and I was able to run my program…

Thank you for the reply I’ll make sure I do that

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.