# Compile error when trying to read customized TObject

**URL:** <https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014>\
**Category:** Newbie\
**Tags:** root\
**Created:** [April 16, 2024, 9:58am UTC](https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014 "2024-04-16T09:58:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [April 16, 2024, 9:58am UTC](https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014/1 "2024-04-16T09:58:59Z")

</div>

Dear experts

I made a customized TObject called `IDriftElectrons` and here is what in `IDriftElectron_LinkDef.h`

```auto
#ifdef __CINT__
#pragma link C++ class COMET::IDriftElectron+;
#pragma link C++ class COMET::IDriftElectronContainer+;
#pragma link C++ class std::vector<COMET::IDriftElectron*>+;
#pragma link C++ class IHandle::<COMET::IDriftElectron>+;
#pragma link C++ class IHandle::<COMET::IDriftElectronContainer>+;
#endif

```

but when I made a app to read this `IDriftElectron` and compile it gives the error:

```auto
CMakeFiles/xt_check.dir/app/xt_check.cxx.o:(.rodata._ZTVN5COMET7IHandleINS_14IDriftElectronEEE[_ZTVN5COMET7IHandleINS_14IDriftElectronEEE]+0x1e0): undefined reference to `COMET::IHandle<COMET::IDriftElectron>::Streamer(TBuffer&)'
CMakeFiles/xt_check.dir/app/xt_check.cxx.o:(.rodata._ZTVN5COMET7IHandleINS_23IDriftElectronContainerEEE[_ZTVN5COMET7IHandleINS_23IDriftElectronContainerEEE]+0x1e0): undefined reference to `COMET::IHandle<COMET::IDriftElectronContainer>::Streamer(TBuffer&)'
CMakeFiles/xt_check.dir/app/xt_check.cxx.o: In function `COMET::IHandle<COMET::IDriftElectron>::IsA() const':
xt_check.cxx:(.text._ZNK5COMET7IHandleINS_14IDriftElectronEE3IsAEv[_ZNK5COMET7IHandleINS_14IDriftElectronEE3IsAEv]+0xd): undefined reference to `COMET::IHandle<COMET::IDriftElectron>::Class()'
CMakeFiles/xt_check.dir/app/xt_check.cxx.o: In function `COMET::IHandle<COMET::IDriftElectron>::ShowMembers(TMemberInspector&) const':
xt_check.cxx:(.text._ZNK5COMET7IHandleINS_14IDriftElectronEE11ShowMembersER16TMemberInspector[_ZNK5COMET7IHandleINS_14IDriftElectronEE11ShowMembersER16TMemberInspector]+0x11): undefined reference to `COMET::IHandle<COMET::IDriftElectron>::Class()'
CMakeFiles/xt_check.dir/app/xt_check.cxx.o: In function `COMET::IHandle<COMET::IDriftElectronContainer>::IsA() const':
xt_check.cxx:(.text._ZNK5COMET7IHandleINS_23IDriftElectronContainerEE3IsAEv[_ZNK5COMET7IHandleINS_23IDriftElectronContainerEE3IsAEv]+0xd): undefined reference to `COMET::IHandle<COMET::IDriftElectronContainer>::Class()'
CMakeFiles/xt_check.dir/app/xt_check.cxx.o: In function `COMET::IHandle<COMET::IDriftElectronContainer>::ShowMembers(TMemberInspector&) const':
xt_check.cxx:(.text._ZNK5COMET7IHandleINS_23IDriftElectronContainerEE11ShowMembersER16TMemberInspector[_ZNK5COMET7IHandleINS_23IDriftElectronContainerEE11ShowMembersER16TMemberInspector]+0x11): undefined reference to `COMET::IHandle<COMET::IDriftElectronContainer>::Class()'
collect2: error: ld returned 1 exit status

```

I’m not sure if these errors are caused by missing of includes, or CMakeList.txt, any advice please?  
What I included:

```auto
#include <TROOT.h>
#include <TFile.h>
#include <TTree.h>
#include <TH2.h>
#include <TH1.h>
#include <TCanvas.h>
#include <TApplication.h>

#include "cometEventLoop.hxx"
#include "IHandle.hxx"
#include "IDriftElectron.hxx"
#include "ICOMETEvent.hxx"

```

---

<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 16, 2024, 10:39am UTC](https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014/2 "2024-04-16T10:39:50Z")

</div>

Hello Siyuan,

This is a linker error.  
Could you double check that to create the `xt_check.cxx.o` unit you expose to the compiler the sources of your classes as well as the ones generated by `rootcling`, i.e. the _dictionaries_?

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [April 16, 2024, 2:11pm UTC](https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014/3 "2024-04-16T14:11:03Z")

</div>

I found that when I compiling the library for `IDriftElectron` it gives two warning:

```auto
Warning: Unused class rule: IHandle::<COMET::IDriftElectronContainer>
Warning: Unused class rule: IHandle::<COMET::IDriftElectron>                                                                                                               

```

but I did write such rule in the LinkDef file, why?

---

<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 16, 2024, 2:42pm UTC](https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014/4 "2024-04-16T14:42:06Z")

</div>

Hello,

Do you have those types in the headers in input to `rootcling`?

Best,  
D

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [April 16, 2024, 2:49pm UTC](https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014/5 "2024-04-16T14:49:08Z")

</div>

Can you specify a little more what is the “headers in input to rootcling”? Sorry I’m not familar to these words…  
If you mean `IDriftElectron_LinkDef.hxx`, yes I have alread put these in as shown at the first post 🙂

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [April 16, 2024, 2:54pm UTC](https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014/6 "2024-04-16T14:54:01Z")

</div>

Oh I just found what was wrong…In my LinkDef.hxx I wrote:

```auto
#ifdef __CINT__
#pragma link C++ class COMET::IDriftElectron+;
#pragma link C++ class COMET::IDriftElectronContainer+;
#pragma link C++ class std::vector<COMET::IDriftElectron*>+;
#pragma link C++ class IHandle::<COMET::IDriftElectron>+;
#pragma link C++ class IHandle::<COMET::IDriftElectronContainer>+;
#endif

```

and as you can see the last two lines are just wrong (missing namespace and scope resolution operator at wrong position)…it should be

```auto
#pragma link C++ class COMET::IHandle<COMET::IDriftElectron>+;
#pragma link C++ class COMET::IHandle<COMET::IDriftElectronContainer>+;

```

Sorrr for asking such a stupid question!

---

<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 16, 2024, 3:06pm UTC](https://root-forum.cern.ch/t/compile-error-when-trying-to-read-customized-tobject/59014/7 "2024-04-16T15:06:52Z")

</div>

Glad you solved it. No question is stupid.
