TMVAClassification.C linkage error

I cannot compile the tutorial’s TMVAClassification.C
After running $(root-config --cxx --cflags) TMVAClassification.C -o tmva_class $(root-config --glibs --libs), I receive errors from linker:

/usr/bin/ld: /tmp/ccxpOIRE.o: in function `TMVAClassification(TString)':
TMVAClassification.C:(.text+0x2f): undefined reference to `TMVA::Tools::Instance()'
/usr/bin/ld: TMVAClassification.C:(.text+0x1074): undefined reference to `TMVA::gTools()'
...
/usr/bin/ld: TMVAClassification.C:(.text+0x3efa): undefined reference to `TMVA::Factory::EvaluateAllMethods()'
/usr/bin/ld: TMVAClassification.C:(.text+0x401c): undefined reference to `TMVA::TMVAGui(char const*, TString)'
collect2: error: ld returned 1 exit status

I tried different permutations the position of libs path, source code, and output, but nothing helped.

I use Root v6.26.02.Linux-ubuntu20-x86_64-gcc9.4 ,
Ubuntu 20.04.4 LTS on WSL2 (5.10.102.1-microsoft-standard-WSL2),
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

Hi @yebondar ,
what about:

$(root-config --cxx) TMVAClassification.C -o tmva_class $(root-config --libs --cflags) -lTMVA

(note the final -lTMVA)?

Cheers,
Enrico

Hm, thanks, now better, but …

/usr/bin/ld: /tmp/ccI67ESa.o: in function `TMVAClassification(TString)':
TMVAClassification.C:(.text+0x401c): undefined reference to `TMVA::TMVAGui(char const*, TString)'
collect2: error: ld returned 1 exit status

NB: ACLIC runs this code well

You need -lTMVAGui as well.

Yep, because it automagically knows which libraries to link :smiley: