ROOT Header files

I am running a simulation that uses root and am having trouble making the program. I have set the ROOT_DIR in the CMakeLists.txt file and it has been built. But then when I go to run the program I have get the following error:

In file included from /home/DetectorSim/EMPHATICSim/emphaticSim.cc:3:
/home/DetectorSim/EMPHATICSim/include/EMPHATICSimAnalysisManager.hh:6:10: fatal error: TTree.h: No such file or directory
6 | #include <TTree.h>
| ^~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/emphaticSim.dir/build.make:76: CMakeFiles/emphaticSim.dir/emphaticSim.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/emphaticSim.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Can anyone offer some advice on resolving this issue?

Rather than setting ROOT_DIR directly, you probably want to use the CMake find_package() action. Doing that should set all of the necessary compiler options. Otherwise, to fix that error, you need to have -I$(ROOTSYS)/include as a compilation option.

I call the method find_package(ROOT REQUIRED) and was getting and error that it couldnt find a rootconfig.cmake file. So i wrote directly above it: set(ROOT_DIR /home/…/cmake).

By using find_package() do you mean passing the location of the root install in the find_package method?

That’s odd. What you did is correct, I think. My only question is whether your ROOT_DIR setting is right. I’m not as familiar with CMake as I should be. Naively, I would have expected you to set ROOT_DIR to point to the same thing that “$ROOTSYS” points to in your shell.

… Okay, try the following (there may be a more proper CMake way to do this). According to ROOTConfig.cmake (which I think is what find_package() loads), you should be able to do

include(${ROOT_USE_FILE})

right after the find_package() line, and it’ll set up the -I and -L flags appropriately for you.

That fixed some of the issues I was having. CMake did not recognize multiple header files. So when I made that change CMake was able to find those headers.

however, there is one it still returning errors for:

fatal error: G4GDMLParser.hh: No such file or directory
16 | #include “G4GDMLParser.hh”

Also I went back and make some changes to how I was specifying the root path. I just specified them in my bashrc file.

That’s weird. This is in a Geant4 build that worked before? Is it finding all of the other Geant4 include files? I see that header file in all of the Geant4 10.* versions (I don’t have 11.00.beta on my Mac).

If you’re doing “export” envvar settings, I’d strongly recommend doing that in your .profile or .bash_profile, not in .bashrc. The latter gets run every time a child shell is created. In particular, every time a Make action happens, a child shell is created. If you configure your session with particular envvar values (e.g., to point to a different ROOT version or something), and you also have those envvar in your .bashrc, the latter will stomp on your careful setup and you won’t get the results you expect.

Thank you so much. I reinstalled geant4 and that fixed the rest of my issues.

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