Compiling Error-> Can't compile

Hello!

I am having trouble compiling an example source code that I know can be compiled by my colleague. I’ve attached the example source code (unfortunately the n-tuple 161992.root is too big and the extension .sh is not allowed). You can compile the example by typing in terminal or making this a bash script:
“g++ example.cc -I$ROOTSYS/include root-config --libs --glibs -o example”

I am using ROOT 5.28/00g and am on a MAC OS X with a version of g++ downloaded from Xcode.

Thank you and I will greatly appreciate any help that can be provided.
David

Here is the error that I receive:

ld: warning: ignoring file /Applications/root28/lib/libCore.so, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /Applications/root28/lib/libCore.so
ld: warning: ignoring file /Applications/root28/lib/libCint.so, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /Applications/root28/lib/libCint.so
ld: warning: ignoring file /Applications/root28/lib/libRIO.so, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /Applications/root28/lib/libRIO.so

(A lot of other warnings for other root libraries that I have not included)

ld: warning: ignoring file /Applications/root28/lib/libGui.so, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /Applications/root28/lib/libGui.so
Undefined symbols for architecture x86_64:
“TApplication::TApplication(char const*, int*, char**, void*, int)”, referenced from:
_main in cc31PZUE.o
“TVersionCheck::TVersionCheck(int)”, referenced from:
__static_initialization_and_destruction_0(int, int)in cc31PZUE.o
“TApplicationImp::ShowMembers(TMemberInspector&)”, referenced from:
vtable for TApplicationImpin cc31PZUE.o
“TApplicationImp::Class()”, referenced from:
TApplicationImp::IsA() const in cc31PZUE.o
“TApplicationImp::Streamer(TBuffer&)”, referenced from:
vtable for TApplicationImpin cc31PZUE.o
“TFile::TFile(char const*, char const*, char const*, int)”, referenced from:
_main in cc31PZUE.o
“TClass::GetClass(std::type_info const&, bool, bool)”, referenced from:
int TTree::SetBranchAddress<std::vector<float, std::allocator > >(char const*, std::vector<float, std::allocator >, TBranch)in cc31PZUE.o
“TObject::operator delete(void*)”, referenced from:
_main in cc31PZUE.o
“TString::~TString()”, referenced from:
TApplicationImp::~TApplicationImp()in cc31PZUE.o
TApplicationImp::~TApplicationImp()in cc31PZUE.o
“TStorage::ObjectAlloc(unsigned long)”, referenced from:
TObject::operator new(unsigned long)in cc31PZUE.o
“TDataType::GetType(std::type_info const&)”, referenced from:
int TTree::SetBranchAddress<std::vector<float, std::allocator > >(char const*, std::vector<float, std::allocator >, TBranch)in cc31PZUE.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
example.cc (841 Bytes)

Try to execute:
root-config --cxx --cflags -o example example.cc root-config --libs

I downloaded a 64 bit binary of root and both solutions work now.

Although when I try to execute a different compiled source code (that I am currently working on) it will always crash after the second iteration of my analysis function (after the first analysis function is used on the first n-tuple, it doesn’t work on the second n-tuple).

I’ll attach my source code and my analysis header. I don’t expect anyone to search through my code but if anything comes to mind quickly I’d really appreciate some help.

Thanks very much,
David

This is the error:

*** Break *** segmentation violation

There was a crash.
This is the entire stack trace of all threads:

Thread 1 (process 1266):
#0 0x00007fff880e96ac in wait4 ()
#1 0x00007fff8c95003a in system ()
#2 0x0000000108f5b715 in TUnixSystem::StackTrace ()
#3 0x0000000108f58e71 in TUnixSystem::DispatchSignals ()
#4
#5 0x0000000108e405e0 in TLorentzVector::operator+ ()
#6 0x0000000108e338bc in analysis ()
#7 0x0000000108e3894e in main ()

The lines below might hint at the cause of the crash.

#5 0x0000000108e405e0 in TLorentzVector::operator+ ()
#6 0x0000000108e338bc in analysis ()
#7 0x0000000108e3894e in main ()

analysiscode-output-index.h (32.1 KB)
maincodetemp.cpp (19.4 KB)

Here is a more detailed error report:

#5 0x0000000103b845e0 in TLorentzVector::operator+ (this=0x7fff5c287238, q=
0x7fff5c088d78) at TLorentzVector.h:375
#6 0x0000000103b778bc in analysis (filename=
0x7fff5c08c2f8, toutput=0x7fff5c08ab28, toutputcut=0x7fff5c08a908, xsec=0.06769, Filter=1, Alpgen=0, Kfactor=1, sameflavour=true, cuts=true, cutflow=false, boosting=true, ZZCR=false) at analysiscode-output-index.h:559
#7 0x0000000103b7c94e in main () at maincodetemp.cpp:177

Right before or after “//IDENTIFYING WHICH LEPTONS CORRESPOND TO THE Z-DECAY” try to add:
indexZleps1 = indexZleps2 = indexOther1 = indexOther2 = 0; // make sure they are always initialized

Brilliant!
Okay thats resolved, another error crash and I don’t know why. This is what it says:

#5 0x0000000103821600 in THStack::Add ()
#6 0x000000010243eb34 in main ()

Presumably referring to line 320.

Thank you so much!
David

Try to modify two lines:
TH1D* Histo[(num-1)] = {0}; // make sure all pointers are null
and:
TH1D* Histo2[(num-1)] = {0}; // make sure all pointers are null

That worked again! But again another crash. So I made sure the pointers were null for all my TCanvas, THStack and TH1D objects.

TCanvas CanvasAfterAllCuts = {0};
CanvasAfterAllCuts= new TCanvas(“CanvasAfterAllCuts”,“CanvasAfterAllCuts”,1);
TCanvas Canvas = {0};
Canvas= new TCanvas(“Canvas”,“Canvas”,1);
THStack
StackedHisto = {0};
StackedHisto= new THStack(“StackedHisto”, “Distribution of the Leptons After All Cuts”);
TH1D
Histo[(num-1)]= {0};
THStack* StackedHisto2 ={0};
StackedHisto2= new THStack(“StackedHisto2”, “Distribution of the Leptons Before Cuts”);
TH1D* Histo2[(num-1)]= {0};
TH1D* HistoZH = {0};
TH1D* Histo2ZH = {0};

This was the error I got.

#5 0x000000010014fd27 in main ()

or

#5 0x0000000109de1d27 in main () at maincodetemp.cpp:440

Sorry for making you debug my code. I really appreciate it.

First, ordinary pointers should be initialized with a simple “0”, not with a “{0}”, for example:
TH1D* HistoZH = 0;
TH1D* Histo2ZH = 0;

Then, remove the string "TH1D* " from the line:
TH1D* Histo2ZH= new TH1D(“ZH Histo2”,“Distribution of the Leptons - ZH Signal”,NumberOfBins,minX,maxX);

And, last but not least, learn how to use “valgrind”:

[url]Free(): invalid next size(fast)//malloc(): memory corruption
[url]Upper limit of entries in one bin and in whole histogram
[url]fTotBytes error
[url]Segmentation Fault in Recursive Removement
[url]Memory leak

BTW. Try simply to execute:
root-config --cxx --cflags -O2 -W -Wall -c maincodetemp.cpp
and carefully inspect all reported warnings (correct your source code so that they all disappear).

Okay no crashes anymore!!!

Except when I run the executable, it doesn’t actually display my histograms or my canvases for that matter. Is that expected or do I need to include something?

Thanks,
David

Try to modify your “main”: [code]// …

#include “TApplication.h”

int main() {
TApplication theApp(“analysiscode”, 0, 0);

// …

theApp.Run(kTRUE); // exit using any canvas main menu -> “File” -> "Quit ROOT"
return 0;
}[/code]

You are a genius. Everything is a go.

Thank you so very much for your help,
David

I beg your pardon but I’m not just a plain ordinary “genius”.
I am Wile E. Coyote - Super Genius.