When I compile an executable (see an example below) with
#!/bin/bash
g++ -std=c++17 $1 `root-config --cflags --glibs` -o PT_CHECKS
I get the following linker error:
/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.:
#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