About Linking CXX executable error,undefined reference to

Hi guys,
when I compile the geant4 program with root using cmake, it compiles successfully but fails when linking with the following error message:

CMakeFiles/EJdetector.dir/src/EJAnalysisManager.cc.o: In function `EJAnalysisManager::book()':
EJAnalysisManager.cc:(.text+0x8d2): undefined reference to `TStorage::ObjectAlloc(unsigned long)'
EJAnalysisManager.cc:(.text+0x8f4): undefined reference to `TFile::TFile(char const*, char const*, char const*, int)'
EJAnalysisManager.cc:(.text+0x900): undefined reference to `TDirectory::CurrentDirectory()'
EJAnalysisManager.cc:(.text+0x90d): undefined reference to `TStorage::ObjectAlloc(unsigned long)'
EJAnalysisManager.cc:(.text+0x92e): undefined reference to `TTree::TTree(char const*, char const*, int, TDirectory*)'
EJAnalysisManager.cc:(.text+0x955): undefined reference to `TTree::Branch(char const*, void*, char const*, int)'
EJAnalysisManager.cc:(.text+0xab9): undefined reference to `TObject::operator delete(void*)'
EJAnalysisManager.cc:(.text+0xacc): undefined reference to `TObject::operator delete(void*)'
CMakeFiles/EJdetector.dir/src/EJAnalysisManager.cc.o: In function `_GLOBAL__sub_I_EJAnalysisManager.cc':
EJAnalysisManager.cc:(.text.startup+0x3b): undefined reference to `TVersionCheck::TVersionCheck(int)'
CMakeFiles/EJdetector.dir/src/EJEventAction.cc.o: In function `_GLOBAL__sub_I_EJEventAction.cc':
EJEventAction.cc:(.text.startup+0x38): undefined reference to `TVersionCheck::TVersionCheck(int)'
CMakeFiles/EJdetector.dir/src/EJRunAction.cc.o: In function `_GLOBAL__sub_I_EJRunAction.cc':
EJRunAction.cc:(.text.startup+0x38): undefined reference to `TVersionCheck::TVersionCheck(int)'

Also, root is used directly via binary and I have tried to execute the command
**source thisroot.sh**

.

Please help me, I’d appreciate it :grinning:!


Please read tips for efficient and successful posting and posting code

_ROOT Version:6.26/02 (binary version)
_Platform:Ubuntu 18
_Compiler:gcc-11 g+±11


Hi @oliver_jamie ,
you are probably not listing the right library dependencies in the cmake files. You can verify with a verbose build (e.g. make VERBOSE=1) whether or not the build even tries to link ROOT libraries to your program. My guess is that it does not (no -lTree or -lRIO in the compilation command), in which case you have to tell cmake about those dependencies (e.g. via a target_link_libraries invocation).

Cheers,
Enrico

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