I am having trouble plotting within my code, so I decided to go back to the basic, I downloaded Rene’s example file, graph.C from tutorials, I run that from CINT, all is fine. The I try to compile it and I get these messages for TGraph and TCanvas:
eniac:~/data/mag/lifu> gcc test_graph.cpp root-config --libs --glibs --ldflags --auxlibs --auxcflags
-L/usr/local/lib/root/ -I /usr/local/include/root/
test_graph.cpp: In function ‘void graph()’:
test_graph.cpp:18: error: invalid use of incomplete type ‘struct TCanvas’
/usr/local/include/root/TROOT.h:36: error: forward declaration of ‘struct TCanvas’
test_graph.cpp:20: error: ‘TGraph’ was not declared in this scope
test_graph.cpp:20: error: ‘gr’ was not declared in this scope
test_graph.cpp:21: error: expected type-specifier before ‘TGraph’
test_graph.cpp:21: error: expected ‘;’ before ‘TGraph’
test_graph.cpp:25: error: invalid use of incomplete type ‘struct TCanvas’
/usr/local/include/root/TROOT.h:36: error: forward declaration of ‘struct TCanvas’
test_graph.cpp:26: error: invalid use of incomplete type ‘struct TCanvas’
/usr/local/include/root/TROOT.h:36: error: forward declaration of ‘struct TCanvas’
test_graph.cpp:32: error: ‘sin’ was not declared in this scope
test_graph.cpp:45: error: invalid use of incomplete type ‘struct TCanvas’
/usr/local/include/root/TROOT.h:36: error: forward declaration of ‘struct TCanvas’
test_graph.cpp:48: error: invalid use of incomplete type ‘struct TCanvas’
/usr/local/include/root/TROOT.h:36: error: forward declaration of ‘struct TCanvas’
Weird thing is that my older code uses the same structure as this (which was probably stolen from the same example) and it compiles without complaining).
I attach my test_graph.cpp code below, thanks
#include <stdlib.h>
#include
#include “TROOT.h”
/*
#include “TVirtualFitter.h”
#include “TMath.h”
#include “TH1.h”
#include “TF1.h”
*/
void graph() {
//Draw a simple graph
// To see the output of this macro, click begin_html here. end_html
//Author: Rene Brun
TCanvas *c1 = new TCanvas(“c1”,“A Simple Graph Example”,800,600);
TGraph *gr = NULL ;
gr = new TGraph(n,x,y);
c1->SetFillColor(42);
c1->SetGrid();
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i0.1;
y[i] = 10sin(x[i]+0.2);
printf(" i %i %f %f \n",i,x[i],y[i]);
}
gr->SetLineColor(2);
gr->SetLineWidth(4);
gr->SetMarkerColor(4);
gr->SetMarkerStyle(21);
gr->SetTitle(“a simple graph”);
gr->GetXaxis()->SetTitle(“X title”);
gr->GetYaxis()->SetTitle(“Y title”);
gr->Draw(“ACP”);
// TCanvas::Update() draws the frame, after which one can change it
c1->Update();
//c1->GetFrame()->SetFillColor(21);
//c1->GetFrame()->SetBorderSize(12);
c1->Modified();
}
int main(){
graph() ;
exit(0) ;
}