I've been scratching my head how to workaround the following problem. This may not actually be a problem with ROOT, but I would really appreciate it if you could take a look and let me know if you have some idea for a workaround.
Let us say you have a class declared in a header file wich looks like this:
And you want to make root dictionary from this class:
Then, this will fail if Qt5 version is recent enough (I have 5.8 but 5.5 should also work) and Qt5 was built with "-reduce-relocations" in its configure flags. The reason is that, if '-reduce-relocations' was used to build Qt5, then "qconfig.h" header (indirectly included in qglobal.h) will include a line that defines QT_REDUCE_RELOCATIONS. And then the problem is that "qglobal.h" uses "#error" to abort compilation unless the user code is compiled with -fPIC. Here's the relevant section of qglobal.h:
Now I admit that this is a nasty thing that they added in Qt. Here are some references:
which explain the rationale behind the code above. But I have to find a way to workaround this issue. We are already compiling all our code with -fPIC. The MyClassDict.cxx would also be compiled with -fPIC, if it were created. The issue is that the rootcling invocation which generates MyClassDict.cxx does not define "_PIC_" and I can't add -fPIC to the rootcling flags since that flag is ignored (see rootcling_impl.cxx "ShouldIgnoreClingArgument").
It works when I add "-D_PIC_" to the rootcling arguments, but that's an ugly hack:
And things are actually even more complicated. While defining _PIC_ on the rootcling commandline works around this particular problem, it doesn't help when trying to compile a macro with TSystem::CompileMacro("macro.C", "kf"), since that will internally construct a rootcling call with some fixed arguments which I can't change, so I don't know how I would inject "-D_PIC_" there.
The next thing I tried is to write a "qglobal.h" wrapper and put it in a place that comes first in my include path. It looks like this:
Now this makes things mostly work, but there are some macros which I can't compile with ACLiC anymore, because after the macro_C.so is generated in TSystem::CompileMacro() it gets loaded with "gSystem->Load()" and in this step root.exe crashes with a segmentation violation, possibly due to the _PIC_ define?!
Now I'm really lost and have no more ideas...