Shared library for class which uses extern struct

Dear ROOTers,
My various attemps failed to make a shared library for a class which uses external C structure.
A short example of code figuring out the problem is in attachment.
MyClass.tar.gz (2.06 KB)

Hello,

I don’t know if this is a legal source code for C/C++.
First, you have struct defined with in a namespace and without extern “C”. Then later, you define the same struct name in extern “C”. I think those are distingushed as different ones by C++ compiler. You have to be consistent. For example,

extern “C” {
struct yourstruct { … }
}
namespace yournamespace {
extern “C” struct yourstruct;
}

Thank you
Masa Goto

Hello,

A variant with the commented description of a structure produces even an error
in MyClassDict.cxx compilation. I just use these structure as prescribed method for
linkage with a fortran common.
I’ve managed to compile, link without ROOT and execute modules with
both variants of the structure description.
Is it possible to emdeb something like this in ROOT?
Valery.

Hello Valery,

Please simplify your code. I see complicated dependency between C and C++ namespace. Commeting out struct definition is not sufficient. I could compile it after separating C and C++ portion.

Thank you
Masa Goto

Hello Masa,

Even if i get rid of the namespace i don’t see the structure.

                                  Thank you for help, Valery.

Hi,

Note that the pragma defined_in requires a full pathname.
So you need to add an explicity request to generate the dictionary for your struct.

Cheers,
Philippe.