error in compiling

Hi!
I am a beginner to c++. I tried to compile and link following code


#include "Pythia.h"
#include "TH1.h"
#include "TTree.h"
#include "TFile.h"
using namespace Pythia8;
int ex1() {
// Generator. Process selection. LHC initialization. Histogram.
Pythia pythia;
pythia.readString("HardQCD:all = on");
pythia.readString("PhaseSpace:pTHatMin = 20.");
pythia.init( 2212, 2212, 14000.);
TFile *file = TFile::Open("ex1.root","recreate");
Event *event = &pythia.event;
TTree *T = new TTree("T","ev1 Tree");
T->Branch("event","Event",&event);
TH1F *mult = new TH1F("mult","charged multiplicity", 100, -0.5, 799.5);
// Begin event loop. Generate event. Skip if error. List first one.
for (int iEvent = 0; iEvent < 100; ++iEvent) {
if (!pythia.next()) continue;
//if (iEvent < 1) {pythia.info.list(); pythia.event.list();}
// Find number of all final charged particles and fill histogram.
int nCharged = 0;
for (int i = 0; i < pythia.event.size(); ++i)
if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
++nCharged;
mult->Fill( nCharged );
T->Fill();
// End of event loop. Statistics. Histogram. Done.
}
pythia.statistics();
cout << mult;
T->Print();
T->Write();
delete file;
return 0;
}


I used the command

g++ -o2 -L$ROOTSYS/lib -L$PYTHIA8/lib -I$ROOTSYS/include -I$PYTHIA8/include main01_r.cc

and i got this


/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
/tmp/cclhLO7b.o(.text+0x148): In function `ex1()':
: undefined reference to `Pythia8::Pythia::Pythia(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/cclhLO7b.o(.text+0x213): In function `ex1()':
: undefined reference to `Pythia8::Pythia::readString(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)'
/tmp/cclhLO7b.o(.text+0x2d5): In function `ex1()':
: undefined reference to `Pythia8::Pythia::readString(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)'
/tmp/cclhLO7b.o(.text+0x374): In function `ex1()':
: undefined reference to `Pythia8::Pythia::init(int, int, double)'
/tmp/cclhLO7b.o(.text+0x392): In function `ex1()':
: undefined reference to `TFile::Open(char const*, char const*, char const*, int, int)'
/tmp/cclhLO7b.o(.text+0x3d7): In function `ex1()':
: undefined reference to `TTree::TTree(char const*, char const*, int)'
/tmp/cclhLO7b.o(.text+0x3f6): In function `ex1()':
: undefined reference to `TObject::operator delete(void*)'
/tmp/cclhLO7b.o(.text+0x47e): In function `ex1()':
: undefined reference to `TH1F::TH1F(char const*, char const*, int, double, double)'
/tmp/cclhLO7b.o(.text+0x49d): In function `ex1()':
: undefined reference to `TObject::operator delete(void*)'
/tmp/cclhLO7b.o(.text+0x4dd): In function `ex1()':
: undefined reference to `Pythia8::Pythia::next()'
/tmp/cclhLO7b.o(.text+0x5ec): In function `ex1()':
: undefined reference to `Pythia8::Pythia::statistics(bool, bool)'
/tmp/cclhLO7b.o(.text+0x67a): In function `ex1()':
: undefined reference to `Pythia8::Pythia::~Pythia()'
/tmp/cclhLO7b.o(.text+0x6a4): In function `ex1()':
: undefined reference to `Pythia8::Pythia::~Pythia()'
/tmp/cclhLO7b.o(.text+0x723): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `TVersionCheck::TVersionCheck(int)'
/tmp/cclhLO7b.o(.gnu.linkonce.t._ZN7TObjectnwEj+0xd): In function `TObject::operator new(unsigned int)':
: undefined reference to `TStorage::ObjectAlloc(unsigned int)'
/tmp/cclhLO7b.o(.gnu.linkonce.t._ZN5TTree6BranchIN7Pythia85EventEEEP7TBranchPKcS6_PPT_ii+0x27):In function `TBranch* TTree::Branch<Pythia8::Event>(char const*, char const*, Pythia8::Event**,int, int)':
: undefined reference to `TBuffer::GetClass(std::type_info const&)'
collect2: ld returned 1 exit status



Can anyone please tell where the problem is?

Thanks in advance!
Please use the code formating tag on the right to format your code.

The first error says your program doesn't provide a function main.
The remainder seem to be caused by you not linking to the right libraries.
Topic archived. No new replies allowed.