Error in during compilation of code undefined reference to `TH1F::TH1F(char const*, char const*, int, double, double)’
Getting this error during make . How to resolve it

Sounds like you’re using ROOT directly, rather than G4analysis. Do you have all the appropriate ROOT #include statements in your code?

Yes I have included ROOT properly, it shows error only in this .cc file.

Could you post your CMakeLists.txt please? I’m guessing that the needed ROOT libraries are not being linked to given the undefined reference errors.

CMakeLists.txt (3.7 KB)

This is my CmakeLists.txt
In old version I was compiling the code without CMakeLists.txt.

Thanks! All that’s needed is to modify the find_package for ROOT to find the components needed:

# Might need additional components depending on what bits of ROOT you use
find_package(ROOT REQUIRED Core RIO Hist)

and then link to the required targets:

target_link_libraries(TestEm4 ${Geant4_LIBRARIES} ${ROOT_LIBRARIES})

Thank you very much , It is working now.