Home | News | Documentation | Download

Can I "include" headers of compiled custom library in a macro?


I complied a library libABC.so and I used it in a maro like:

root -l libABC.so

then I can use classes from libABC.so in ROOT prompt like:

ClassABC* x = new ClassABC

This works only without including ClassABC.h.
When ClassABC.h is included, ClassABC becomes a incomplete type ( since it’s defined in ClassABC.cxx) and has a problem with stl vector, here’s the first few lines of the error:

In module 'std' imported from input_line_1:1:
/usr/include/c++/7/bits/stl_vector.h:671:50: error: arithmetic on a pointer to an incomplete type 'MEEvent'
      { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
                         ~~~~~~~~~~~~~~~~~~~~~~~ ^
/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEReconstructManager.hh:44:40: note: in instantiation of member function 'std::vector<MEEvent, std::allocator<MEEvent> >::size' requested here
    int GetNLoaded(){return mEventData.size();}
libME dictionary forward declarations' payload:6:121: note: forward declaration of 'MEEvent'
class __attribute__((annotate("$clingAutoload$/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEEvent.hh")))  MEEvent;
Error in <TInterpreter::AutoParse>: Error parsing payload code for class METrack with content:

#line 1 "libME dictionary payload"

// Inline headers
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEEvent.hh"
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEEventFactory.hh"
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEGUIFrame.hh"
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEGeoExtract.hh"
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MELib.hh"
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEManager.hh"
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEProcessedFile.hh"
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/MEReconstructManager.hh"
#include "/home/yanghang/Project/MuGrid-EventDisplayApp/app/include/METrack.hh"

This problem can be avoided by simply not including headers from my custom library, however, doing so disables the auto-completion feature of IDE. More importantly, these errors indicates that I may have done something in a wrong way.
My goal is to make this library behave like those built-in libraries of ROOT. For example, I can use TCanvas in macro with or without TCanvas.h included. What is the correct way to do so?


Do you header file have the usual code guards?

Yes, there are include guards.

As an update, I found that this problem will not occur if my custom class doesn’t have any std::vector members.