TH1D.hh header not found

Hello, following the Anaex02 example I was including in my simulation the headers

#include <TH1D.h>
#include <TFile.h>
#include <TTree.h>

but I get the error


i.e. it can’t find TH1D

Does it need some special installation settings?
I’m using windows

Thank you

Those are ROOT classes. Do you have your ROOT installation included in your environment? At a minimum, you should see an environment variable $ROOTSYS set, pointing to the ROOT installation.

Typically you get it set up with source <root-install-path>/bin/thisroot.sh on a Unix system.

Read the ROOT documentation to find out what to do on a Windows machine.

See also examples/extended/analysis/AnaEx02 for how to find and link to ROOT using CMake.

Thank you the both @mkelsey and @bmorgan

Yes, to lunch ROOT I use the commands

C:\root_v6.26.02\bin\thisroot.bat
root

then the enviroment variable should be correctly setted.

I hadded the code

#----------------------------------------------------------------------------
# Find ROOT (required package)
#
find_package(ROOT REQUIRED)

but I still get the error

C:\B1\src\StackingAction.cc(40,10): fatal error C1083: Non è possibile aprire il file inclusione: 'TH1D.h': No such fil
e or directory [C:\B1\B1-build\exampleB1.vcxproj]

Given that I use my Geant only to test the simulation, but I lunch it on laboratory machine (where it is installed cvmfs), I also tried to lunch it on laboratory machine but it doesn’t work on cvmfs too…

[100%] Linking CXX executable exampleB1
CMakeFiles/exampleB1.dir/src/StackingAction.cc.o: In function `__static_initialization_and_destruction_0':
/cvmfs/sft.cern.ch/lcg/views/LCG_geant4ext20201111/x86_64-centos7-gcc8-opt/include/TVersionCheck.h:31: undefined reference to `TVersionCheck::TVersionCheck(int)'
collect2: error: ld returned 1 exit status
make[2]: *** [exampleB1] Error 1
make[1]: *** [CMakeFiles/exampleB1.dir/all] Error 2
make: *** [all] Error 2

CMakeError.log.txt (1.5 KB)

Just finding ROOT isn’t sufficient, the application must also be linked to the ROOT libraries, see this line in the linked example’s CMake script

Depending on the ROOT version, it may also be necessary to use include_directories to point the build to the relevant include path

Hello @borgan, then I added

#----------------------------------------------------------------------------
# Locate sources and headers for this project
# NB: headers are included so they will show up in IDEs
#
include_directories(${PROJECT_SOURCE_DIR}/include
                    ${PROJECT_SOURCE_DIR}/shared/include
                    ${Geant4_INCLUDE_DIR}
                    ${ROOT_INCLUDE_DIRS})
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc
                  ${PROJECT_SOURCE_DIR}/shared/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh
                  ${PROJECT_SOURCE_DIR}/shared/include/*.hh)
#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(exampleB1 exampleB1.cc ${sources} ${headers})
target_link_libraries(exampleB1 ${Geant4_LIBRARIES} ${ROOT_LIBRARIES})

CMakeLists.txt (2.9 KB)

but now I get the warnings and errors


C:\B1\B1-build>cmake --build . --config Release
Microsoft (R) Build Engine versione 16.11.2+f32259642 per .NET Framework
Copyright (C) Microsoft Corporation. Tutti i diritti sono riservati.

  Checking Build System
  Building Custom Rule C:/B1/CMakeLists.txt
  exampleB1.cc
  B1ActionInitialization.cc
  B1DetectorConstruction.cc
  B1EventAction.cc
  B1PrimaryGeneratorAction.cc
  B1Run.cc
  B1RunAction.cc
  B1SteppingAction.cc
  DetectorMessenger.cc
  MGGerdaLocalMaterialTable.cc
  StackingAction.cc
  gem90PhysListEmLowEnergy.cc
  gem90PhysListHadron.cc
  gem90PhysListParticles.cc
  gem90PhysicsList.cc
  gem90PhysicsListMessenger.cc
C:\root_v6.26.02\include\TString.h(509,58): warning C4273: '_stricmp': collegamento dll non coerente (compilazione del
file di origine C:\B1\src\StackingAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\string.h(189,22): message : vedere la precedente defin
izione di '_stricmp' (compilazione del file di origine C:\B1\src\StackingAction.cc) [C:\B1\B1-build\exampleB1.vcxproj]
StackingAction.obj : error LNK2019: riferimento al simbolo esterno "public: __cdecl TVersionCheck::TVersionCheck(int)"
(??0TVersionCheck@@QEAA@H@Z) non risolto nella funzione "void __cdecl ROOT::Internal::`dynamic initializer for 'gVersio
nCheck''(void)" (??__EgVersionCheck@Internal@ROOT@@YAXXZ) [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libCore.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tip
o 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libImt.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tipo
 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libRIO.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tipo
 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libNet.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tipo
 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libHist.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tip
o 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libGraf.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tip
o 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libGraf3d.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il t
ipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libGpad.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tip
o 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libROOTDataFrame.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto c
on il tipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libTree.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tip
o 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libTreePlayer.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con
il tipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libRint.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il tip
o 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libPostscript.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con
il tipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libMatrix.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il t
ipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libPhysics.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il
tipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libMathCore.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il
 tipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libThread.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con il t
ipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\root_v6.26.02\lib\libROOTVecOps.lib : warning LNK4272: il tipo 'x86' del computer della libreria è in conflitto con
il tipo 'x64' del computer di destinazione [C:\B1\B1-build\exampleB1.vcxproj]
C:\B1\B1-build\Release\exampleB1.exe : fatal error LNK1120: 1 esterni non risolti [C:\B1\B1-build\exampleB1.vcxproj]

and I also get errors using cvmfs

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