ROOT Canvas for C++ files

I have writen a C++ file with ROOT libraries and a Makefile for compiling that, the executable file is good, but doesn’t show the graphics, only shows the numbers in terminal.

Are you using TApplication in your program ?

I have a program for a gui, in this program I use TApplication, but the program related to this topic doesn’t use TApplication, only TCanvas, TMath, and TGraph.

To render graphics in a canvas in a standalone program you need one.

The file is called curva.cxx, when I compile root -l curva.cxx do all. Shows the numbers in terminal and shows the graphics on canvas, when I make the executable using compiler g++ only shows the numbers in terminal. I use this line g++ root-config --glibs --cflags -o curva curva.cxx

Yes this is expected. To run your program standalone outside root ( your second case) you need to have a TApplication in your program.

Of course I include TApplication, do the same, shows de numbers in terminal but doesn’t plot the function. This the curva.cxx file

using namespace std;
void curva(){

  TCanvas *c;
  TGraph *g;
  Int_t N;
  double x,y,min,max;
  c=new TCanvas("c","Ver",200,100,700,500);
  //c=new TCanvas("c","Ver");
  g=new TGraph();
  cout<<"ingrese el número de puntos: ";
  cout<<"ingrese el mínimo: ";
  cout<<"ingrese el máximo: ";
  for(int i=0;i<=N;i++){
  //g=new TGraph(N,x,y);
  c-> Update();
  c-> Modified();
int main(Int_t argc, Char_t** argv){
  return 0;
int main(Int_t argc, Char_t** argv){
   TApplication theApp("App", &argc, argv);
   return 0;

Wow, thank you. Process successful. :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.