# 'undefined reference' error after adding a library

**URL:** <https://root-forum.cern.ch/t/undefined-reference-error-after-adding-a-library/56333>\
**Category:** Newbie\
**Created:** [September 11, 2023, 1:02pm UTC](https://root-forum.cern.ch/t/undefined-reference-error-after-adding-a-library/56333 "2023-09-11T13:02:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sbecka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/7c8e57/32.png) [@Sbecka](https://root-forum.cern.ch/u/Sbecka)\
**Post date:** [September 11, 2023, 1:02pm UTC](https://root-forum.cern.ch/t/undefined-reference-error-after-adding-a-library/56333/1 "2023-09-11T13:02:59Z")

</div>

Hello,  
I have a short script that reads a tree from a root file and generates a canvas showing a signal. The script works fine. However, I needed to add a library file called ‘libTParameters.so’ from another directory in my Makefile. After adding the file, I got an error message as follows:

/usr/bin/ld: /projects/scode/libTParameters.so: undefined reference to `TPID::Reset()’

TPID is a class and the header file where it is declared is in the /projects/scode/include directory.  
My current working directory is separate from either of these. Therefore I have explicitly included the TPID.h file in my script.

What I understood so far that the library that I have added was not linked properly. Can you please help me figuring out what I am missing? I am attaching the code and the Makefile herein .

Thank you.

\_ROOT Version: v6.24/06  
[plot.cpp](https://root-forum.cern.ch/uploads/short-url/7s0b517vj8SnduFLuEr5F0K9tx7.cpp) (1.9 KB)  
[Makefile.txt](https://root-forum.cern.ch/uploads/short-url/ecZwoXjjI8DWK9RbBjZcLdpIdJu.txt) (943 Bytes)

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [September 18, 2023, 8:00am UTC](https://root-forum.cern.ch/t/undefined-reference-error-after-adding-a-library/56333/2 "2023-09-18T08:00:14Z")

</div>

Dear @Sbecka ,

The library being added also needs to be able to reach your header file. You can for example extend the include paths seen by ROOT via [gInterpreter-\>AddIncludePath](https://root.cern.ch/doc/master/classTCling.html#a57397ee37ebbf8cbbb54387eb77e02af) .

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![Sbecka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/7c8e57/32.png) [@Sbecka](https://root-forum.cern.ch/u/Sbecka)\
**Post date:** [September 25, 2023, 2:15am UTC](https://root-forum.cern.ch/t/undefined-reference-error-after-adding-a-library/56333/3 "2023-09-25T02:15:30Z")

</div>

I have added this in my .cpp file and received the following error,  
error: expected constructor, destructor, or type conversion before ‘-\>’ token  
gInterpreter-\>AddIncludePath(“Path\_to\_include”);

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [September 25, 2023, 8:10pm UTC](https://root-forum.cern.ch/t/undefined-reference-error-after-adding-a-library/56333/4 "2023-09-25T20:10:13Z")

</div>

Hi @Sbecka ,

It is not really clear to me what you are doing exactly. In any case, have you included the right headers? `gInterpreter` is defined `TInterpreter.h` so that should be included in your program. Also, make sure you use it inside the scope of a function and before you try to load your external library.

Cheers,  
Vincenzo
