Hi,
I’m trying to use a shared library containing classes with inheritance. Unfortunately, I am running into some compatibility problems and in the current state can’t use the library both with the interpreter and the compiler at the same time. Help would be appreciated.
For example, I have class A and a shared library A.sl as well as a class B which inherits from class A:
#ifndef _B
#define _B
#include "A.h"
class B : public A {
public:
B(int arg) : A(arg) {}
void funcB();
};
#endif
Now, when I compile this macro:
#include "A.h"
#include "B.h"
void macro() {
A a(0);
a.funcA();
B b(0);
b.funcA();
}
Everything works nicely.
However, when I load the library with gSystem->Load("A.sl");
and then execute the macro without compiling it I get the errors:
error: base class has incomplete type
class B : public A {
~~~~~~~^
A.h:5:7: note: definition of 'A' is not complete until the closing '}'
class A {
^
In file included from ADictUX dictionary payload:6:
B.h:7:15: error: type 'A' is not a direct or virtual base of 'B'
B(int arg) : A(arg) {}
^
Error in <TInterpreter::AutoParse>: Error parsing payload code for class A with content:
#line 1 "ADictUX dictionary payload"
#define _BACKWARD_BACKWARD_WARNING_H
// Inline headers
#include "A.h"
#include "B.h"
#undef _BACKWARD_BACKWARD_WARNING_H
Error in <TInterpreter::AutoParse>: Error parsing payload code for class B with content:
#line 1 "ADictUX dictionary payload"
#define _BACKWARD_BACKWARD_WARNING_H
// Inline headers
#include "A.h"
#include "B.h"
#undef _BACKWARD_BACKWARD_WARNING_H
Now, I can avoid the these errors by including only
#pragma link off all classes;
in the LinkDef.h. Unfortunately, this is not really an option since it makes the library unusable for example with ROOT.gSystem.Load('A.sl')
.
Is there a way to make all three options work at the same time? If needed I can also attach the full example.