Run tmva on a standalone application using g++

Hi all,
I have a code, where I am using the TMVA factory in order to train a Neural Network. I want to execute it, outside of CINT, so, I import all the headers but when I am trying:

I get these messages

In function `main': trainTMVA.cpp:27: undefined reference to `TMVA::Factory::Factory(TString, TFile*, TString)' trainTMVA.cpp:29: undefined reference to `TMVA::Factory::AddSignalTree(TTree*, double, TMVA::Types::ETreeType)' trainTMVA.cpp:30: undefined reference to `TMVA::Factory::AddBackgroundTree(TTree*, double, TMVA::Types::ETreeType)' trainTMVA.cpp:32: undefined reference to `TMVA::Factory::SetWeightExpression(TString const&, TString const&)' trainTMVA.cpp:34: undefined reference to `TMVA::Factory::AddVariable(TString const&, char, double, double)' trainTMVA.cpp:35: undefined reference to `TMVA::Factory::AddVariable(TString const&, char, double, double)' trainTMVA.cpp:36: undefined reference to `TMVA::Factory::AddVariable(TString const&, char, double, double)' trainTMVA.cpp:37: undefined reference to `TMVA::Factory::AddVariable(TString const&, char, double, double)' trainTMVA.cpp:38: undefined reference to `TMVA::Factory::AddVariable(TString const&, char, double, double)' /tmp/ccTzjrLe.o:trainTMVA.cpp:39: more undefined references to `TMVA::Factory::AddVariable(TString const&, char, double, double)' follow /tmp/ccTzjrLe.o: In function `main': trainTMVA.cpp:52: undefined reference to `TMVA::Factory::PrepareTrainingAndTestTree(TCut const&, TString const&)' trainTMVA.cpp:57: undefined reference to `TMVA::Factory::BookMethod(TMVA::Types::EMVA, TString, TString)' trainTMVA.cpp:58: undefined reference to `TMVA::Factory::BookMethod(TMVA::Types::EMVA, TString, TString)' trainTMVA.cpp:59: undefined reference to `TMVA::Factory::BookMethod(TMVA::Types::EMVA, TString, TString)' trainTMVA.cpp:61: undefined reference to `TMVA::Factory::TrainAllMethods()' trainTMVA.cpp:63: undefined reference to `TMVA::Factory::TestAllMethods()' trainTMVA.cpp:65: undefined reference to `TMVA::Factory::EvaluateAllMethods()' collect2: error: ld returned 1 exit status

the $TMVASYS variable is already set.
What is going wrong?

Thank you in advance!

Try to add “-lTMVA”.

It works like a charm!!!
Thank you so much Pepe!!