# Problem using ROOT in a Geant4 project

**URL:** <https://root-forum.cern.ch/t/problem-using-root-in-a-geant4-project/38008>\
**Category:** Newbie\
**Tags:** cmake\
**Created:** [February 17, 2020, 11:13am UTC](https://root-forum.cern.ch/t/problem-using-root-in-a-geant4-project/38008 "2020-02-17T11:13:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joanna-Gao](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/joanna-gao/32/21539_2.png) [@Joanna-Gao](https://root-forum.cern.ch/u/Joanna-Gao)\
**Post date:** [February 17, 2020, 11:13am UTC](https://root-forum.cern.ch/t/problem-using-root-in-a-geant4-project/38008/1 "2020-02-17T11:13:10Z")

</div>

Hi,

I am trying to simulate a cube of water with neutrons shooting into it and extract the information of energy deposition using Geant4. The main body of my code is adapted from Geant4 basic example B1, minus the two volumes and changing the particle from gamma to neutron. I tried to use TFile and TTree to store my data - I added the following code to B1RunAction.cc, RunAction::BeginOfRunAction(const G4Run\*) function.

```auto
-----------------------------------------------------------------------
outputFile = new TFile("test.root", "RECREATE");
Data = new TTree("Data", "Information of particles");
Data->Branch("Initial", &InitialEnergy, "fInitial/D");
Data->Branch("Final", &FinalEnergy, "fFinal/D");
Data->Branch("Energy Deposition", &Edep, "fEdep/D");
Data->Branch("RMS of Energy Deposition", &rmsEdep, "rmsEdep");
-----------------------------------------------------------------------

```

and in RunAction::EndOfRunAction(const G4Run\* run) I added

```auto
---
Data->Write();
outputFile->Close();
---

```

I think I’ve defined everything properly in the header file and initialised the variables after the RunAction::RunAction() : G4UserRunAction(). I also made sure to change my CMakeFiles.txt to include the locations of the ROOT headers by adding these:

```auto
find_package(ROOT REQUIRED)
include(${ROOT_USE_FILE})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

```

but when I make the files after running cmake command successfully, I keep getting this error:

```auto
-----------------------------------------------------------------------
[37%] Linking CXX executable exampleB1
Undefined symbols for architecture x86_64:
  "TVersionCheck::TVersionCheck(int)", referenced from:
      __GLOBAL__ sub_I_exampleB1.cc in exampleB1.cc.o
      __GLOBAL__ sub_I_ActionInitialization.cc in ActionInitialization.cc.o
      __GLOBAL__ sub_I_EventAction.cc in EventAction.cc.o
      __GLOBAL__ sub_I_RunAction.cc in RunAction.cc.o
  "TFile::TFile(char const*, char const*, char const*, int)", referenced from:
      RunAction::RunAction() in RunAction.cc.o
  "TTree::TTree(char const*, char const*, int)", referenced from:
      RunAction::RunAction() in RunAction.cc.o
  "TObject::operator delete(void*)", referenced from:
      RunAction::RunAction() in RunAction.cc.o
  "TStorage::ObjectAlloc(unsigned long)", referenced from:
      RunAction::RunAction() in RunAction.cc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [exampleB1] Error 1
make[1]: *** [CMakeFiles/exampleB1.dir/all] Error 2
make: *** [all] Error 2

```

* * *

I understand this error “Undefined symbols for architecture x86\_64” means my definition of variables is inconsistent at some locations, but I can’t figure out where to fix it. Please can you point out where I did wrong? Sorry I’m really new to C++.

\_ROOT Version: 5.34.36  
\_Geant4 Version: 10.5.1  
\_Platform: Catalina 10.15.3  
\_Compiler: cmake 3.16.3

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [February 17, 2020, 12:14pm UTC](https://root-forum.cern.ch/t/problem-using-root-in-a-geant4-project/38008/2 "2020-02-17T12:14:18Z")

</div>

It appears it is a Geant4 problem. You should post on [their forum](https://geant4-forum.web.cern.ch/).

---

<div class="post-metadata">

**Author:** ![Joanna-Gao](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/joanna-gao/32/21539_2.png) [@Joanna-Gao](https://root-forum.cern.ch/u/Joanna-Gao)\
**Post date:** [February 17, 2020, 12:25pm UTC](https://root-forum.cern.ch/t/problem-using-root-in-a-geant4-project/38008/3 "2020-02-17T12:25:37Z")

</div>

Thank you! I’ll try posting there.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 17, 2020, 9:45pm UTC](https://root-forum.cern.ch/t/problem-using-root-in-a-geant4-project/38008/4 "2020-02-17T21:45:05Z")

</div>

You probably need to add something like:

```auto
add_dependencies(exampleB1 Core RIO)

```

in your CMakeList.txt file. I.e. you need to link against the ROOT libraries.
