# How to #include \<myownheader.h\> in rootlogon.C

**URL:** <https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643>\
**Category:** ROOT\
**Tags:** root\
**Created:** [July 12, 2023, 3:51pm UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643 "2023-07-12T15:51:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cxwx1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/cxwx1/32/22433_2.png) [@cxwx1](https://root-forum.cern.ch/u/cxwx1)\
**Post date:** [July 12, 2023, 3:51pm UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/1 "2023-07-12T15:51:02Z")

</div>

* * *

\_ROOT Version:6.29.01  
\_Platform:macos

* * *

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`

> [@Can I "include" headers of compiled custom library in a macro?](https://root-forum.cern.ch/t/can-i-include-headers-of-compiled-custom-library-in-a-macro/44251):
>
> Hello. I complied a library libABC.so and I used it in a maro like: root -l libABC.so then I can use classes from libABC.so in ROOT prompt like: ClassABC\* x = new ClassABC x-\>fun() ... This works only without including ClassABC.h. When ClassABC.h is included, ClassABC becomes a incomplete type ( since it’s defined in ClassABC.cxx) and has a problem with stl vector, here’s the first few lines of the error: In module 'std' imported from input\_line\_1:1: /usr/include/c++/7/bits/stl\_vector.h…

how ever I could use

```auto
gInterpreter->ProcessLine("#include<myownclass.h>");

```

in prompt, but it’s a little slower  
an other way is to` #include ".cc"` file (I don’t want the way )

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 12, 2023, 3:53pm UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/2 "2023-07-12T15:53:59Z")

</div>

Hi @cxwx1 ,

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`).

---

<div class="post-metadata">

**Author:** ![cxwx1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/cxwx1/32/22433_2.png) [@cxwx1](https://root-forum.cern.ch/u/cxwx1)\
**Post date:** [July 12, 2023, 4:23pm UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/3 "2023-07-12T16:23:13Z")

</div>

Is there a faster way, using `gInterpreter` always cause 2 second to load the header file.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 12, 2023, 4:35pm UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/4 "2023-07-12T16:35:45Z")

</div>

`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:

```bash
/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.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [July 12, 2023, 5:03pm UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/5 "2023-07-12T17:03:14Z")

</div>

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`).

---

<div class="post-metadata">

**Author:** ![cxwx1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/cxwx1/32/22433_2.png) [@cxwx1](https://root-forum.cern.ch/u/cxwx1)\
**Post date:** [July 12, 2023, 5:16pm UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/6 "2023-07-12T17:16:06Z")

</div>

> [@pcanal](#):
>
> f you generated a dictionary for your classes, you should just have to load the library (and if you gene

I try to use

```auto
R__LOAD_LIBRARY(libmy.so) 
#include <my.h>

```

but it seem che root prompt always starting with `#include ` file first before other operation.  
so the only way is to use `gInterpreter`?

---

<div class="post-metadata">

**Author:** ![cxwx1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/cxwx1/32/22433_2.png) [@cxwx1](https://root-forum.cern.ch/u/cxwx1)\
**Post date:** [July 20, 2023, 8:37am UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/7 "2023-07-20T08:37:37Z")

</div>

I use header `yaml-cpp` and `spdlog`, the two lib’s header cause long time loading whenever using `Declare` or `ProcessLine `?

> **[GitHub - jbeder/yaml-cpp: A YAML parser and emitter in C++](https://github.com/jbeder/yaml-cpp)**
>
> A YAML parser and emitter in C++. Contribute to jbeder/yaml-cpp development by creating an account on GitHub.

> **[GitHub - gabime/spdlog: Fast C++ logging library.](https://github.com/gabime/spdlog)**
>
> Fast C++ logging library. Contribute to gabime/spdlog development by creating an account on GitHub.

can I speed up the without compiling the script?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 20, 2023, 3:32pm UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/8 "2023-07-20T15:32:52Z")

</div>

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.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![cxwx1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/cxwx1/32/22433_2.png) [@cxwx1](https://root-forum.cern.ch/u/cxwx1)\
**Post date:** [July 21, 2023, 8:45am UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/9 "2023-07-21T08:45:36Z")

</div>

thanks, it worked, but still cause ~1 second,  
I modify rootlogon.C with

```auto
gSystem->Load("myheader_h.so");

```

`Real Time = 1.12 seconds Cpu Time = 1.12 seconds`  
may be there are too many template on that two librarys.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [August 4, 2023, 8:46am UTC](https://root-forum.cern.ch/t/how-to-include-myownheader-h-in-rootlogon-c/55643/10 "2023-08-04T08:46:21Z")

</div>

Closed on August 4, 2023, 8:46am UTC

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