Hi, all,
I’d want to load my own class when open ROOT prompt using rootlogon.C
when I use #include <myownheader.h> in rootlogon.C
meet the same problem with incomplete type
I guess you need to both include the header (with gInterpreter->ProcessLine or gInterpreter->Declare) and load the library (with gInterpreter->Load or gSystem->Load).
Declare might be faster than ProcessLine. 2 seconds seems like a lot though. Starting up the ROOT prompt and running a gInterpreter->Declare takes 0.2 seconds on my laptop.
This test uses ROOT v6.28.00 installed via conda:
/tmp cat myclass.h
class C {
int a = 42;
int b = 0;
};
/tmp /usr/bin/time root -l -q -e 'gInterpreter->Declare("#include \"myclass.h\"")'
(bool) true
Command exited with non-zero status 1
0.14user 0.06system 0:00.21elapsed 100%CPU (0avgtext+0avgdata 266788maxresident)k
0inputs+0outputs (0major+23739minor)pagefaults 0swaps
/tmp /usr/bin/time root -l -q -e 'gInterpreter->Declare("#include \"myclass.h\"")'
(bool) true
Command exited with non-zero status 1
0.15user 0.06system 0:00.21elapsed 100%CPU (0avgtext+0avgdata 266888maxresident)k
0inputs+8outputs (0major+23717minor)pagefaults 0swaps
EDIT:
I obtain similar runtimes with current head of the ROOT master branch compiled from source.
If you generated a dictionary for your classes, you should just have to load the library (and if you generate a rootmap or a module file as part of the dictionary generation, this loading should be automatic as long as the library location is in the LD_LIBRARY_PATH).
If I understand correctly, when ROOT starts up you immediately declare to the interpreter your own class, which depends on yaml-cpp and spdlog. This is quite a bit of functionality that the interpreter has to just-in-time-compile. 2 seconds does not seem unreasonable for that as a one-time start-up cost. I bet g++ or clang++ would take a similar amount of time.
Maybe one thing you could try is to load your class with .L myclass.h+ (or the equivalent via gSystem->CompileMacro) which should skip recompilation after the first time.