Hi Vincent,
If you want to run a Root graphics application (interactive
or batch), you must create a TApplication (or TRint) control
object in your program. See many examples (hworld.cxx) in test.
I have modified your main program (see below) accordingly.
To run your program interactively, do
hello
To run your program in batch, do
hello -b
You can type
hello -?
to see the list of all possible options. This produces:
hello -?
Just do it!
Usage: hello [-l] [-b] [-n] [-q] [dir] [file1.C ... fileN.C]
Options:
-b : run in batch mode without graphics
-n : do not execute logon and logoff macros as specified in .rootrc
-q : exit after processing command line macro files
-l : do not show splash screen
dir : if dir is a valid directory cd to it before executing
//-----------------------------
#include <iostream.h>
#include "TApplication.h"
#include <TROOT.h>
#include <TFile.h>
#include <TCanvas.h>
int main (int argc, char **argv)
{
cout<<"Just do it!"<<endl;
// init ROOT system
TROOT root("Hello","hello");
TApplication theApp("App", &argc, argv);
// Create output file
TCanvas *c1 = new TCanvas("c1");
c1->SetGrid();
TFile *file = new TFile("hello.txt","RECREATE","P'tit test entre
amis",2);
file->Close();
theApp.Run();
}
Rene Brun
On Sat, 4 Mar 2000, Pascal Vincent wrote:
>
> Hello,
>
> I do not know if the following problem already appears in this mailing
> list but please, help me.
>
> I have a compiled ROOT program which run in background or in batch and
> which does not need to access the X serveur of my PC. But when it run on
> a remote host, I have a crash if the access to my display is denied?!?!?
>
> First let me introduce myself : I use
> - ROOT version 2.23
>
> and
>
> - Linux 2.2.10/RedHat 5.0
> - My c++ compilator is egcs-1.1.2 release.
> - libc.so.6
>
> or
>
> - Linux 2.0.36/Slackware.
> - C++ compilator is gcc version 2.7.2.2
> - libc.so.5
>
>
> As we can imagine I have a very big and beautiful program but, try this
> simple example:
>
> //-----------------------------
> #include <iostream.h>
> #include "TROOT.h"
> #include "TFile.h"
>
> extern void InitGui();
> VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
>
> int main (int argc, char **argv)
> {
> cout<<"Just do it!"<<endl;
>
> // init ROOT system
> TROOT root("Hello","hello", initfuncs);
>
> // Create output file
> TFile *file = new TFile("hello.txt","RECREATE","P'tit test entre amis",2);
> file->Close();
> }
> // ---------------- That's all
>
> Then compile with
>
> g++ -O -Wall -fPIC -I/usr/local/root/include -c test.C
>
> for gcc or
>
> g++ -O -fno-rtti -fno-exceptions -Wall -fPIC -I/usr/local/root/include
> -c test.C
>
> for egcs and then link with :
>
> g++ test.o -L/usr/local/root/lib -lCore -lCint -lHist -lGX11
> -lGraf -lGraf3d -lGpad -lTree -lProof -lRint -lPostscript -lMatrix
> -lPhysics -lNew -lGpad -lGX11 -lX3d -lXpm -L/usr/X11R6/lib -lXm -lXext
> -lXt -lX11 -lg++ -ldl -rdynamic -L/usr/lib -lm -o hello
>
> Run the program "hello" on remote host, accessed from your terminal by
> telnet.
>
> It Works! nice...
>
> Then remove the remote host name from X control list : xhost -<remote>
>
> Now run it again. It crash with the standard well known message :
>
> Xlib: connection to "<local>:0.0" refused by server
> Xlib: Client is not authorized to connect to Server
> Error in <TGClient::TGClient>: can't open display "<local>:0", bombing...
>
> Now, you can say : "Why do you deny the access to your remote machine?".
>
> Event if I allow all machine over the world to access my display
> with "xhost +" command (I don't do that), unfortunatly I lock the screen
> of my PC when I leave my office. So each night all batch job crash for the
> same reason (I refuse to work day and night...). And anyway my program
> don't need this authority.
>
> Ok there is something wrong in the compilation. If I keep only the minimal
> list of library needed for the load, for example :
>
> g++ test.o -L/usr/local/root/lib -lCore -lCint -L/usr/X11R6/lib
> -lXm -lXext -lXt -lX11 -lg++ -ldl -rdynamic -L/usr/lib -lm -o hello
>
> It works again ! I am the most happiest guy in the world!
>
> But I can not control all libraries for each new line added in my code.
> Could you say to me which library is responsible of this? It seems to me
> that the beavior of some functionnality of ROOT is handled by different
> libraries. If (as I think) the containt of the ROOT libraries is involved
> in this behavior, that could makes ROOT unreliable.
>
> What do you think about my probleme ? Maybe I am totally wrong.
>
> Thanks for your help,
> Pascal.
>
>
> for HESS Collaboration : http://www-hfm.mpi-hd.mpg.de/HESS/HESS.html
> ======================================================================
> Pascal Vincent LPNHE IN2P3-CNRS-Universite Paris VI & VII
> 4, Place Jussieu - BP 200 - Tour 33 Rdc, 75252 PARIS cedex 05 - France
> Tel: 01 44 27 48 43 Fax: 01 44 27 46 38 e-mail: vincentp@in2p3.fr
> WWW: http://www-lpnhep.in2p3.fr/delphi/vincentp/ .................
> ======================================================================
>
>
>
>
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:20 MET