Undefined reference to TUnuran when compiling with g++

_ROOT Version:6.16.00
_Platform: CentOS 7
Compiler: Not Provided


I’m trying to write a small Monte Carlo and one of the variables (wind speed) has an empirical probability density function, that’s why I’m using Unuran libraries which integrate this feature very efficiently.
I have rebuilt ROOT with -Dunuran=ON and now when I run root-config --has-unuran the answer is yes, but when I try to compile my macro with

g++ -o accident macro.cpp `root-config --cflags --libs` source/Source.cpp source/Utility.cpp source/Transport.cpp source/Output.cpp source/OuterSource.cpp source/Dispersion.cpp source/Dose.cpp

It returns the following error:

/tmp/cc7qm2IW.o: In function `StandaloneApplication(int, char**)':
macro.cpp:(.text+0x209): undefined reference to `TUnuran::TUnuran(TRandom*, unsigned int)'
macro.cpp:(.text+0x28e): undefined reference to `TUnuran::Init(TUnuranEmpDist const&, std::string const&)'
macro.cpp:(.text+0x424): undefined reference to `TUnuran::Sample()'
macro.cpp:(.text+0x677): undefined reference to `TUnuran::~TUnuran()'
macro.cpp:(.text+0x7ab): undefined reference to `TUnuran::~TUnuran()'
/tmp/cc7qm2IW.o: In function `TUnuranBaseDist::~TUnuranBaseDist()':
macro.cpp:(.text._ZN15TUnuranBaseDistD2Ev[_ZN15TUnuranBaseDistD5Ev]+0x13): undefined reference to `vtable for TUnuranBaseDist'
/tmp/cc7qm2IW.o: In function `TUnuranEmpDist::~TUnuranEmpDist()':
macro.cpp:(.text._ZN14TUnuranEmpDistD2Ev[_ZN14TUnuranEmpDistD5Ev]+0x13): undefined reference to `vtable for TUnuranEmpDist'
/tmp/cc7qm2IW.o: In function `TUnuranBaseDist::TUnuranBaseDist()':
macro.cpp:(.text._ZN15TUnuranBaseDistC2Ev[_ZN15TUnuranBaseDistC5Ev]+0xf): undefined reference to `vtable for TUnuranBaseDist'
/tmp/cc7qm2IW.o: In function `TUnuranEmpDist::TUnuranEmpDist<__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > > >(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, unsigned int)':
macro.cpp:(.text._ZN14TUnuranEmpDistC2IN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEEEET_S8_j[_ZN14TUnuranEmpDistC5IN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEEEET_S8_j]+0x2b): undefined reference to `vtable for TUnuranEmpDist'
collect2: error: ld returned 1 exit status

The macro I’m trying to compile is attached
macro.cpp (2.5 KB)

I’m afraid there’s something I’m missing in the compile step, but I have no idea of what could be.

Thank you so much for your help

You probably need to add by hand -lUnuran, since root-config doesn’t add it by default. Cheers,

Thank you, it worked.

I imagined was that simple but i didn’t know the syntax.

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