Compile error when trying to read customized TObject

Dear experts

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

#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:

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:

#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"

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

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

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?

Hello,

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

Best,
D

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 :slight_smile:

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

#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

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

Sorrr for asking such a stupid question!

Glad you solved it. No question is stupid.