# Compile issue with Library paths

**URL:** <https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127>\
**Category:** Newbie\
**Created:** [April 24, 2024, 4:02pm UTC](https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127 "2024-04-24T16:02:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dyson\_Kennedy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dyson_kennedy/32/36338_2.png) [@Dyson\_Kennedy](https://root-forum.cern.ch/u/Dyson_Kennedy)\
**Post date:** [April 24, 2024, 4:02pm UTC](https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127/1 "2024-04-24T16:02:25Z")

</div>

\_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

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!

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [April 24, 2024, 5:42pm UTC](https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127/2 "2024-04-24T17:42:25Z")

</div>

Try:

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

```

---

<div class="post-metadata">

**Author:** ![Dyson\_Kennedy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dyson_kennedy/32/36338_2.png) [@Dyson\_Kennedy](https://root-forum.cern.ch/u/Dyson_Kennedy)\
**Post date:** [April 24, 2024, 6:20pm UTC](https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127/3 "2024-04-24T18:20:41Z")

</div>

Thanks,  
That gives me

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

```

So its still not finding the root files.

I amended my .bashrc to be

```export
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

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [April 24, 2024, 6:32pm UTC](https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127/4 "2024-04-24T18:32:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dyson\_Kennedy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dyson_kennedy/32/36338_2.png) [@Dyson\_Kennedy](https://root-forum.cern.ch/u/Dyson_Kennedy)\
**Post date:** [April 24, 2024, 6:37pm UTC](https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127/5 "2024-04-24T18:37:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [April 24, 2024, 7:13pm UTC](https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127/6 "2024-04-24T19:13:26Z")

</div>

> [@Dyson\_Kennedy](#):
>
> That gives me

Sorry my bad. My copy-paste was wrong ☹

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

```

---

<div class="post-metadata">

**Author:** ![Dyson\_Kennedy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dyson_kennedy/32/36338_2.png) [@Dyson\_Kennedy](https://root-forum.cern.ch/u/Dyson_Kennedy)\
**Post date:** [April 24, 2024, 7:39pm UTC](https://root-forum.cern.ch/t/compile-issue-with-library-paths/59127/7 "2024-04-24T19:39:13Z")

</div>

Thank you very much!
