Compile issue with Library paths

_ROOT Version: 6.30/06
Built for linuxx8664gcc on Apr 03 2024, 10:34:21
From tags/v6.30.06@v6.30.06
_Platform: Ubuntu 20.04.6 LTS
_Compiler:g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0

I am trying to compile my code read_root_file.cpp using the command
g++ `root-config --cflags --libs` -o read_root_file read_root_file.cpp
However, I’m getting
/usr/bin/ld: /scratch/login/cc1xfIL7.o: in function `main': read_root_file.cpp:(.text+0xc6): undefined reference to `TFile::Open(char const*, char const*, char const*, int, int)' /usr/bin/ld: read_root_file.cpp:(.text+0x1f3): undefined reference to `TTree::Class()' /usr/bin/ld: /scratch/login/cc1xfIL7.o: in function `__static_initialization_and_destruction_0(int, int)': read_root_file.cpp:(.text+0x521): undefined reference to `TVersionCheck::TVersionCheck(int)' /usr/bin/ld: /scratch/login/cc1xfIL7.o: in function `TIter::TIter(TCollection const*, bool)': read_root_file.cpp:(.text._ZN5TIterC2EPK11TCollectionb[_ZN5TIterC5EPK11TCollectionb]+0x1c): undefined reference to `vtable for TIter' /usr/bin/ld: /scratch/login/cc1xfIL7.o: in function `TIter::~TIter()': read_root_file.cpp:(.text._ZN5TIterD2Ev[_ZN5TIterD5Ev]+0x13): undefined reference to `vtable for TIter' collect2: error: ld returned 1 exit status

My .bashrc has this


export ROOTSYS=/home/dkennedy_umass_edu/root
export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$ROOTSYS/lib

and just running this
root-config --cflags --libs

gives me
-pthread -std=c++17 -m64 -I/home/dkennedy_umass_edu/root/include -L/home/dkennedy_umass_edu/root/lib -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -Wl,-rpath,/home/dkennedy_umass_edu/root/lib -pthread -lm -ldl -rdynamic

If anyone can help point out what PATH I’m missing or messing up or if its a different issue, that would be much appreciated!

Thanks,
Dyson!

Try:

g++ `root-config --libs` -o read_root_file read_root_file.cpp `root-config --libs`

Thanks,
That gives me

    6 | #include <TFile.h>
      |          ^~~~~~~~~
compilation terminated.

So its still not finding the root files.

I amended my .bashrc to be

export PATH=$PATH:$ROOTSYS/bin                                                                          export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH                                                                              export LD_LIBRARY_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$LD_LIBRARY_PATH                                                     export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$ROOTSYS/lib                                                                export LD_LIBRARY_PATH=/home/dysontravis/MG5_aMC_v3_5_4/Delphes:/home/dysontravis/MG5_aMC_v3_5_4/ExRootAnalysis/ExRootAnalysis:$LD_LIBRARY_PATH                                                                                                 export ROOT_INCLUDE_PATH=/home/dysontravis/MG5_aMC_v3_5_4/Delphes/external:/home/dysontravis/MG5_aMC_v3_5_4/Delphes/classes:$ROOT_INCLUDE_PATH    

But it still ain’t finding the root files

Dear Dyson,

The issue about not finding TFile.h is a fundamental issue with your setup: it means that the compiler cannot find the header in the paths it’s traversing. Could you please double-check all the “-I” paths that the command root-config --cflags --libs --glibs outputs and verify that at least one of them points to the directory where the ROOT headers are stored?

Best,
D

Hello!
Yes, I checked and home/dkennedy_umass_edu/root/include/ has all the header files and that is the first one that root-config --cflags --libs --glibs gives. -pthread -std=c++17 -m64 -I/home/dkennedy_umass_edu/root/include.
That’s why I’m confused.

Sorry my bad. My copy-paste was wrong :frowning:

g++ `root-config --cflags` -o read_root_file read_root_file.cpp `root-config --libs

Thank you very much!