# Linker Error: undefined reference to \`TDatabasePDG::TDatabasePDG()'

**URL:** <https://root-forum.cern.ch/t/linker-error-undefined-reference-to-tdatabasepdg-tdatabasepdg/50256>\
**Category:** Newbie\
**Tags:** root\
**Created:** [June 3, 2022, 12:54pm UTC](https://root-forum.cern.ch/t/linker-error-undefined-reference-to-tdatabasepdg-tdatabasepdg/50256 "2022-06-03T12:54:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://root-forum.cern.ch/u/andrew)\
**Post date:** [June 3, 2022, 12:54pm UTC](https://root-forum.cern.ch/t/linker-error-undefined-reference-to-tdatabasepdg-tdatabasepdg/50256/1 "2022-06-03T12:54:14Z")

</div>

When I compile an executable (see an example below) with

```auto
#!/bin/bash
g++ -std=c++17 $1 `root-config --cflags --glibs` -o PT_CHECKS

```

I get the following linker error:

```auto
/cvmfs/sft.cern.ch/lcg/releases/binutils/2.36.1-a9696/x86_64-centos8/bin/ld: /tmp/andreas/ccm3L0aA.o: in function `main':
example.cpp:(.text+0x1a): undefined reference to `TDatabasePDG::GetParticle(int) const'
/cvmfs/sft.cern.ch/lcg/releases/binutils/2.36.1-a9696/x86_64-centos8/bin/ld: /tmp/andreas/ccm3L0aA.o: in function `__static_initialization_and_destruction_0(int, int)':
example.cpp:(.text+0xa6): undefined reference to `TDatabasePDG::TDatabasePDG()'
/cvmfs/sft.cern.ch/lcg/releases/binutils/2.36.1-a9696/x86_64-centos8/bin/ld: example.cpp:(.text+0xb5): undefined reference to `TDatabasePDG::~TDatabasePDG()'
collect2: error: ld returned 1 exit status

```

which probably means that some library is not included in the `--glibs` argument (?). I have created a code to recreate the issue: e.g.:

```auto
#include <iostream>
#include <TDatabasePDG.h>
TDatabasePDG GDatabase;

int main(int ac, char *av[])
{
	auto new_particle = GDatabase.GetParticle(11); // Electron
	std::cout << new_particle->Mass() << std::endl;
	return 1;
}

```

Works otherwise flawlessly when I run it with `root -x`.

* * *

_ROOT Version:_ 6.24/06  
_Platform:_ Centos08  
_Compiler:_ g++ (GCC) 11.1.0

* * *

---

<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:** [June 3, 2022, 1:05pm UTC](https://root-forum.cern.ch/t/linker-error-undefined-reference-to-tdatabasepdg-tdatabasepdg/50256/2 "2022-06-03T13:05:03Z")

</div>

Hello @andrew ,  
you can see at the bottom of [ROOT: TDatabasePDG Class Reference](https://root.cern/doc/master/classTDatabasePDG.html) that this functionality is contained in `libEG`, which is likely not part of the default set of libraries listed by `--libs` and `--glibs`. If you can use the class from the root prompt, then the library is available, you probably just have to link it. Try using e.g. `g++ -std=c++17 $1 -o PT_CHECKS $(root-config --cflags --glibs) -lEG`.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![andrew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://root-forum.cern.ch/u/andrew)\
**Post date:** [June 3, 2022, 1:09pm UTC](https://root-forum.cern.ch/t/linker-error-undefined-reference-to-tdatabasepdg-tdatabasepdg/50256/3 "2022-06-03T13:09:29Z")

</div>

> [@eguiraud](#):
>
> g++ -std=c++17 1 -o PT\_CHECKS (root-config --cflags --glibs) -lEG

Hi @eguiraud,

Works flawlessly and this is exactly what I was looking for! Thanks a lot!

Yours,

Andreas

---

<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:** [June 3, 2022, 1:12pm UTC](https://root-forum.cern.ch/t/linker-error-undefined-reference-to-tdatabasepdg-tdatabasepdg/50256/4 "2022-06-03T13:12:36Z")

</div>

`root-config --evelibs`
