Root installation in ubuntu check

Hi,

I am trying to check my root installation by compiling a simple script:

test.C is my script:

#include <TApplication.h>
#include <TCanvas.h>

int test() {

TApplication app = new TApplication();

TCanvas canv = new TCanvas();

canv.Draw();

app.Run();

return 0;

}

but when I am trying to compile and run this I get:

$ root test.C


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.31/01 31 May 2011 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

ROOT 5.31/01 (trunk@41666, Nov 01 2011, 07:13:36 on linux)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing test.C…
Error: can not call private or protected function test.C:6:
(compiled) 0 TApplication TApplication::TApplication();
Calling : TApplication::TApplication();
Match rank: file line signature
ffffffff (compiled) 0 TApplication TApplication::TApplication(const
char*,Int_t*,char**,void*,Int_t);

  •    0 (compiled)   0 TApplication TApplication::TApplication();
    
    ffffffff (compiled) 0 TApplication TApplication::TApplication(const TApplication&);
    *** Interpreter error recovered ***
    root [1] .q

Is there something wrong in my installation or am I doing something stupid #-o ?

Thank you,

Best regards,

Cristian

Either: TApplication app; TCanvas canv; canv.Draw(); app.Run(); or: TApplication *app = new TApplication(); TCanvas *canv = new TCanvas(); canv->Draw(); app->Run();

Thank you for your reply. I have tried both and neither works for my trunk installation :frowning: :

code test.C contains:

#include <TApplication.h>
#include <TCanvas.h>

int test() {
/*
TApplication app;
TCanvas canv;
canv.Draw();
app.Run();
*/
// OR
TApplication *app = new TApplication();
TCanvas *canv = new TCanvas();
canv->Draw();
app->Run();

return 0;

}

Running it it gives:

$ root test.C


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.31/01 31 May 2011 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

ROOT 5.31/01 (trunk@41666, Nov 01 2011, 07:13:36 on linux)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing test.C…
Error: can not call private or protected function test.C:15:
(compiled) 0 TApplication TApplication::TApplication();
Calling : TApplication::TApplication();
Match rank: file line signature
ffffffff (compiled) 0 TApplication TApplication::TApplication(const char*,Int_t*,char**,void*,Int_t);

  •    0 (compiled)   0 TApplication TApplication::TApplication();
    
    ffffffff (compiled) 0 TApplication TApplication::TApplication(const TApplication&);
    *** Interpreter error recovered ***
    root [1]

I am using the trunk version on Ubuntu 11.10.

Please let me know any suggestions.

Best regards,

Cristian

You need TApplication only if you write your own “main” (i.e. a standalone compiled program).
In the case that you show, remove everything related to it.

This small script was suggested by the Geant4 collaborators following some geant4-root linking problems. The (geant4) code compiles (and runs) fine if I use only TFile and TH1F classes to create a root file and fill histograms. But as soon as I try to introduce a canvas or pad, it complains of undefined references to TCanvas and TPad.

They said that this is likely a problem related to my ROOT set up, and not Geant4, and asked me to compile that simple script, to check my root installation.

I don’t know how to compile it (g++ would obviously not work, and I have no makefile for it to use make), rather than using ROOT to run it (.x test.C) :blush:

I would be very grateful for any suggestions on how a novice could compile this small code as a standalone compiled program.

Thank you,

Cristian

g++ root-config --cflags -o app app.cxx root-config --glibs
./app
app.cxx (379 Bytes)

[quote]Error: can not call private or protected function test.C:15:
(compiled) 0 TApplication TApplication::TApplication();

Is there something wrong in my installation or am I doing something stupid ?[/quote]When creating a TApplication object you must past some parameter. So far those error do not indicate any problem with the ROOT installation but with the script itself.

To fix you script (since the purpose is only to test the installation) just remove the line about TApplication.

Cheers,
Philippe.

Thank you very much for your reply. I have tested it and an empty canvas is opened without any warning or error messages, as expected.

So why there are those linking errors when I try to define a canvas in my geant4 application remains a mystery :confused: . But my root installation seems fine, and I can live just fine with having only the root file and histograms defined in my code. I was just wondering what could be the problem with canvases.

Anyway, thank you very much for your help, at least now I know how to compile a root script.

Best regards,

Cristian

Hi Christian,

It is my understanding that Geant4 (and in particular their makefiles) has not been ported to Ubuntu 11 and it’s more stringent linking requirements.

Cheers,
Philippe.

Hello Philippe,

Yes, Ubuntu 11.10 is not officially supported by them, but I have managed to install Geant without error messages and all example codes they have seem to compile and run fine on my machine.

Best regards,

Cristian