# Problems adding a custom class using rootcling

**URL:** <https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884>\
**Category:** Cling\
**Tags:** rootcling\
**Created:** [July 17, 2021, 11:11am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884 "2021-07-17T11:11:37Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 17, 2021, 11:11am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/1 "2021-07-17T11:11:38Z")

</div>

Hello,

I want to add a custom class to ROOT, and I’m using the [following](https://github.com/eguiraud/root_dictionaries_tutorial/tree/main/from_the_command_line_with_rootcling) tutorial by @eguiraud . I am using the rootcling way.

My problem is that, once I have used rootcling to make the dictionaries, I want to compile it with g++ using `g++ -o TFeynman_readwrite TFeynman_readwrite.cpp $(root-config --libs --cflags) TFeynman.cxx TFeynman_dict.cpp `. When I do this I get the following error:

```auto
/usr/bin/ld: /home/advait/rootbuild/lib/libGpad.so: undefined reference to symbol '_ZN6TLatexC1EddPKc'
/usr/bin/ld: /home/advait/rootbuild/lib/libGraf.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

```

After doing some digging online, apparently I have to add -lpthread to the command line. Is this correct? And if yes, how do I do this? Here are my files:

> **[AdvaitDhingra/TFeynman](https://github.com/AdvaitDhingra/TFeynman)**
>
> A ROOT extension for making quick Feynman Diagrams. - AdvaitDhingra/TFeynman

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 17, 2021, 11:56am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/2 "2021-07-17T11:56:53Z")

</div>

UPDATE: When I use the cmake method I get this error:

```auto
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o: in function `__static_initialization_and_destruction_0(int, int)':
TFeynman.cxx:(.text+0x1958): undefined reference to `ROOT::GenerateInitInstance(TFeynmanEntry const*)'
/usr/bin/ld: TFeynman.cxx:(.text+0x197c): undefined reference to `ROOT::GenerateInitInstance(TFeynman const*)'
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o: in function `TFeynman::IsA() const':
TFeynman.cxx:(.text._ZNK8TFeynman3IsAEv[_ZNK8TFeynman3IsAEv]+0x11): undefined reference to `TFeynman::Class()'
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o: in function `TFeynman::ShowMembers(TMemberInspector&) const':
TFeynman.cxx:(.text._ZNK8TFeynman11ShowMembersER16TMemberInspector[_ZNK8TFeynman11ShowMembersER16TMemberInspector]+0x15): undefined reference to `TFeynman::Class()'
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o:(.data.rel.ro._ZTV8TFeynman[_ZTV8TFeynman]+0x90): undefined reference to `TFeynman::Streamer(TBuffer&)'
/usr/bin/ld: CMakeFiles/TFeynman.dir/TFeynman.cxx.o:(.data.rel.ro._ZTV8TFeynman[_ZTV8TFeynman]+0x288): undefined reference to `non-virtual thunk to TFeynman::Streamer(TBuffer&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/TFeynman.dir/build.make:110: TFeynman] Error 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/TFeynman.dir/all] Error 2

```

I have no clue what it means 😅

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [July 18, 2021, 10:27pm UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/3 "2021-07-18T22:27:46Z")

</div>

Hi @AdvaitDhingra,

> [@AdvaitDhingra](#):
>
> ```auto
> /usr/bin/ld: /home/advait/rootbuild/lib/libGraf.so: error adding symbols: DSO missing from command line
> 
> ```

You are missing a `-lGraf` on the compiler command line, i.e. that shared object provides the `TLatex::TLatex()` constructor. It seems that it is not included by default in the list provided by `root-config --libs`; adding that option manually should fix your issue.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 18, 2021, 10:39pm UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/4 "2021-07-18T22:39:33Z")

</div>

Ah okay, thanks. I’ll try it and let you know.

---

<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 19, 2021, 8:06am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/5 "2021-07-19T08:06:46Z")

</div>

Actually `root-config --libs` should contain `-lGraf`, it might be an ordering problem.

E.g. you might need

```auto
g++ -o TFeynman_readwrite TFeynman_readwrite.cpp TFeynman.cxx TFeynman_dict.cpp $(root-config --libs --cflags) 

```

instead of

```auto
g++ -o TFeynman_readwrite TFeynman_readwrite.cpp $(root-config --libs --cflags) TFeynman.cxx TFeynman_dict.cpp

```

For the cmake version: does the example in the [GitHub - eguiraud/root\_dictionaries\_tutorial: A tutorial on creating ROOT dictionaries to perform I/O of custom C++ classes](https://github.com/eguiraud/root_dictionaries_tutorial) repository work for you? If not, there might be something broken in your environment. If yes, you could investigate what you changed exactly from the original example that broke it.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 19, 2021, 9:38am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/6 "2021-07-19T09:38:08Z")

</div>

> [@eguiraud](#):
>
> `g++ -o TFeynman_readwrite TFeynman_readwrite.cpp $(root-config --libs --cflags) TFeynman.cxx TFeynman_dict.cpp`

I tried this and I get another error:

```auto
/usr/bin/ld: /tmp/ccm9ljFH.o: in function `__static_initialization_and_destruction_0(int, int)': TFeynman.cxx:(.text+0x1958): undefined reference to `ROOT::GenerateInitInstance(TFeynmanEntry const*)' collect2: error: ld returned 1 exit status  

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 19, 2021, 9:42am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/7 "2021-07-19T09:42:52Z")

</div>

Try:

```bash
`root-config --cxx --cflags` -o TFeynman_readwrite TFeynman_readwrite.cpp TFeynman.cxx TFeynman_dict.cpp `root-config --libs`

```

---

<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 19, 2021, 9:47am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/8 "2021-07-19T09:47:26Z")

</div>

This error means that the source file or library that defines `ROOT::GenerateInitInstance(TFeynmanEntry const*)` needs to be present in your compilation command and it needs to come _after_ `TFeynman.cxx`, which needs that symbol.

I guess `ROOT::GenerateInitInstance(TFeynmanEntry const*)` should be defined in `TFeynman_dict.cpp`, is it there?

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 19, 2021, 9:56am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/9 "2021-07-19T09:56:39Z")

</div>

Yeah, it’s there. Here it is:

```auto
TGenericClassInfo *GenerateInitInstance(const ::TFeynman*){                                                                                                                          
    return GenerateInitInstanceLocal((::TFeynman*)nullptr);
}  

```

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 19, 2021, 9:57am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/10 "2021-07-19T09:57:21Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> `r`

```auto
Unknown argument "--cflagsroot-config"! 
Usage: root-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--auxcflags] [--ldflags] [--new] [--nonew] [--libs] [--glibs] [--evelibs] [--bindir] [--libdir] [--incdir] [--etcdir] [--tutdir] [--srcdir] [--noauxcflags] [--noauxlibs] [--noldflags] [--has-<feature>] [--arch] [--platform] [--config] [--features] [--ncpu] [--git-revision] [--python-version] [--python2-version] [--python3-version] [--cc] [--cxx] [--f77] [--ld] [--help]  

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 19, 2021, 9:59am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/11 "2021-07-19T09:59:45Z")

</div>

Copy and paste the line that I gave you as is without any modifications (and execute it in a bash shell).

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 19, 2021, 10:01am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/12 "2021-07-19T10:01:49Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> `root-config --cxx --cflags` -o TFeynman_readwrite TFeynman_readwrite.cpp TFeynman.cxx TFeynman_dict.cpp `root-config --libs`

I did, and I get the output above. I just accidentally deleted some of your solution when I was quoting it.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 19, 2021, 10:03am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/13 "2021-07-19T10:03:05Z")

</div>

That is NOT the full line.

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 19, 2021, 10:05am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/14 "2021-07-19T10:05:50Z")

</div>

![2021-07-19](https://root-forum.cern.ch/uploads/default/original/3X/c/5/c5918a5eb303f6b8633f24f829262263f462f485.png)

Is this not what you proposed above?  
`root-config --cxx --cflags` -o TFeynman_readwrite TFeynman_readwrite.cpp TFeynman.cxx TFeynman_dict.cpp `root-config --libs`

---

<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 19, 2021, 10:07am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/15 "2021-07-19T10:07:56Z")

</div>

That’s not the symbol that’s missing, the linker complains about `GenerateInitInstance(TFeynmanEntry const*)`, not `GenerateInitInstance(const TFeynman*)`.

Is `TFeynmanEntry` also in your LinkDef? If not maybe try adding it?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 19, 2021, 10:11am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/16 "2021-07-19T10:11:14Z")

</div>

As @eguiraud says, it is clear now that it is not a missing library but a missing entry in the dictionary.

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [July 19, 2021, 11:26am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/17 "2021-07-19T11:26:18Z")

</div>

That worked! Thank you very much @eguiraud and @Wile_E_Coyote .

---

<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 2, 2021, 11:26am UTC](https://root-forum.cern.ch/t/problems-adding-a-custom-class-using-rootcling/45884/18 "2021-08-02T11:26:28Z")

</div>

Closed on August 2, 2021, 11:26am UTC

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