Missing include

Hi,

following code:

[code]#include
#include
#include

#include <RooRealVar.h>

#include <TFile.h>
#include <TH1D.h>

using namespace std;

// evil hack - what the fuck?
RooRealVar x;

const string filename = “foo.root”;
const string histoname = “foo/bar”;

int main(int argc, char *argv[]) {
TFile *file = new TFile(filename.c_str(), “READ”);

TH1D *h = (TH1D*) file->Get(histoname.c_str());
cout << "h->GetEntries(): " << h->GetEntries() << endl;

file->Close();
delete file;

return EXIT_SUCCESS;

}[/code]
works fine because of the command “RooRealVar x;”. Leaving out this command leads to an error at runtime (after compiling successfully):

[code]Warning in TClass::TClass: no dictionary for class TH1D is available
Warning in TClass::TClass: no dictionary for class TH1 is available
Warning in TClass::TClass: no dictionary for class TAxis is available
Error in TBufferFile::CheckByteCount: object of class TNamed read too few bytes: 18 instead of 2164

*** Break *** segmentation violation

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

#0 0x00007fc98e1a098c in __libc_waitpid (pid=12033, stat_loc=stat_loc
entry=0x7fffc5ce9e00, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:31
#1 0x00007fc98e125592 in do_system (line=) at …/sysdeps/posix/system.c:148
#2 0x00007fc98f0a73a3 in TUnixSystem::StackTrace() () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#3 0x00007fc98f0a907c in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#4
#5 0x0000000000000000 in ?? ()
#6 0x0000000000400ffe in main (argc=1, argv=0x7fffc5cec4e8) at main.cpp:23

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x0000000000000000 in ?? ()
#6 0x0000000000400ffe in main (argc=1, argv=0x7fffc5cec4e8) at main.cpp:23

[/code]
Does anyone understand this behaviour? Maybe some missing includes? #-o

Try:

// ... #include "TApplication.h" // ... int main(int argc, char *argv[]) { TApplication a("a", 0, 0); // just to make sure that the autoloading of ROOT libraries works // ...

thanks, that works. But it seems to me as the same magic like just saying “RooRealVar x;” :frowning:

Saying “RooRealVar x;” is “black magic”, creating a proper “TApplication” object is “white magic”.

ok, thx :wink: