Trying to show histogram with executable

Hi, I’m a beginner with root.

I’m trying to do an executable that when run delivers a histogram.
This so far is my simple code:

//Lots of libraries
#include <iostream>                 // class for inputoutput streams
#include <stdio.h>                  // printf, scanf, puts, NULL
#include <stdlib.h>                 // srand, rand, atof
#include <time.h>                   // time
#include <fstream>                  // class for inputoutput file streams
#include <dirent.h>
#include <string.h>           // class to manipulate strings
#include <sstream>                    // class for parsing strings
#include <vector>
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TH1F.h>
#include <TF1.h>
#include <TCanvas.h>
#include <TPaveStats.h>
#include <TPad.h>
#include <TMath.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TLegend.h>
#include <TString.h>
#include <TGraph.h>
#include <TLatex.h>



#include <unistd.h>
#define GetCurrentDir getcwd

#include <TTree.h>

using namespace std;
int main(int argc, char* argv[])
{
  if(argc!= 1 ) return 3; 
  TFile* file = TFile::Open("/Users/Fer/Documents/traajo/samples/NeroNtuples_9.root"); // TFile::Open() instead of a constructor since it works over xrootd etc.
  
  TH1F * h1 = new TH1F("h1","Mi histograma" , 100, 0, 10); 
  h1 = (TH1F*)file->Get("rho"); 
  h1->Draw();

  return 0;
}

And it obviously doesn’t work.

The error I get is this

*** Break *** segmentation violation Generating stack trace...

Someone told it me it may be my make file, but I hope it isn’t because it is a black box to me and it works for everyone else.

Thanks a lot

Add [code]if(argc!= 1 ) return 3;
TApplication app = new TApplication(“app”, &argc, argv);
TFile
file = TFile::Open("/Users/Fer/Documents/traajo/samples/NeroNtuples_9.root");
// TFile::Open() instead of a constructor since it works over xrootd etc.

TH1F * h1 = new TH1F(“h1”,“Mi histograma” , 100, 0, 10);
h1 = (TH1F*)file->Get(“rho”);
h1->Draw();
app.Run();[/code]
and do not forget to include “TApplication.h”

[code]#include “TApplication.h”
#include “TFile.h”
#include “TH1.h”

#include

int main(int argc, char **argv)
{
TApplication *app = new TApplication(“app”, &argc, argv);

if(argc != 1) return 3;

TFile *file =
TFile::Open("/Users/Fer/Documents/traajo/samples/NeroNtuples_9.root");
if ((!file) || file->IsZombie()) { delete file; return 2; }

TH1F *h1;
file->GetObject(“rho”, h1);
if (!h1) { std::cout << “No rho.” << std::endl; delete file; return 1; }
h1->Draw();

app->Run(kTRUE); // any canvas “main menu” -> “File” -> “Quit ROOT”

delete file; // automatically deletes “h1”, too
return 0;
}[/code]