Building custom library: issue when including custom-installed headers in macro

Hi,

I’m building a custom library to analyze and simulate some detector data using ROOT classes. Recently, I moved to a scheme where I have subfolders for each component (Analysis, Simulation,…) and compile them separately. I told CMake to do so and install the headers and libraries (+ dicts) in an install dir. So far so good, but then I’m encountering a problem when including those custom headers in ROOT macros.

I narrowed down the issue to the test.zip file you have attached. If you compile it with these instructions once you unpack it:

mkdir build && cd build
cmake .. & make -jN install

Then in the install folder, you will have the includes and the libs. You have to source the thisTest.sh file to update the LD_LIBRARY_PATH and the ROOT_INCLUDE_PATH to point to that folder.

However, if you try to execute the testSimu.cxx macro ROOT will issue the following:

In the file included from libTestPhysics dictionary payload:5:
/media/Data/test/Physics/Kinematics.h:11:18: error: field has incomplete type 'ActPhysics::Particle'
        Particle fPart;
                 ^
libTestPhysics dictionary forward declarations' payload:5:175: note: forward declaration of 'ActPhysics::Particle'
namespace ActPhysics{class __attribute__((annotate("$clingAutoload$Physics/Particle.h")))  __attribute__((annotate("$clingAutoload$/media/Data/test/Physics/Kinematics.h")))  Particle;}
                                                                                                                                                                              ^
Error in <TInterpreter::AutoParse>: Error parsing payload code for class ActPhysics::Particle with content:

#line 1 "libTestPhysics dictionary payload"


#define _BACKWARD_BACKWARD_WARNING_H
// Inline headers
#include "/media/Data/test/Physics/Kinematics.h"
#include "/media/Data/test/Physics/Particle.h"

#undef  _BACKWARD_BACKWARD_WARNING_H

This only happens when you include the fundamental header Physics/Particle.h first; if you include the Physics/Kinematics.h first (which depends on it), no issue at all!? According to the error log seems something related to the dictionary payload (although they are correctly located in the lib dir)… I had not experienced this issue until I divided the library into subfolders… Maybe somehow ROOT is unable to locate the correct header? But why in such a way that depends on the include order? I tried pointing ROOT_INCLUDE_PATH to the original headers (not the ones under install dir) but the issue is the same.

I would highly appreciate any explanation for this. Thanks in advance!


test.zip (5,2 KB)

ROOT Version: 6.28/02
Platform: Ubuntu 22.04
Compiler: Precompiled binary for that distro


Hi,

Maybe @vvassilev has an explanation for this. However, since you generate the dictionary you don’t need to add any include in your macro. So I would avoid adding them and I would remove both

Lorenzo

Hi!

Thanks for the reply. Yes, I am aware of that. But what happens is that some IDEs require including the header files to provide code completion (which is very useful when working with these programs), so I would like to keep writing them.

I found a workaround: modify the CMake structure of the program to not work with subdirectories when including headers in the source code (#include "Physics/Particle.h changed to #include "Particle.h"). In so doing, no errors are prompted… But still, I am wondering why the previous structure was troublesome.

Greetings!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.