G++ can not run the simple case in root primer

I am new to root, so right now I just run the example in root primer:

[code] #include “TF1.h”

#ifndef CINT
int main()
TF1 *f1 = new TF1(“f1”,“sin(x)/x”,0.,10.);
return 0;

and then g++ source.cpp -lHist -lCore to compile the source file and it generate executable file a.out.

However, I run ./a.out, it said that
Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1
*** Error in `./a.out’: double free or corruption (!prev): 0x0000000001584fc0 ***

I want to ask how to make such simple example work? Because it totally work in ROOT interactive shell.


I think that’s because when Draw() called, TCanvas is automatically called as well, but there’s no reference for it.

Just add all the cflags and libs using root-config like

g++ source.cpp root-config --cflags --libs

That will work without errors.
But, nothing comes out.

I already follow your procedure, it does not help. The same problem appear. I just download Linux RHEL 6 (SLC6) x86-64 with gcc 4.8, version 5.34.21 binary and use ubuntu g++ to compile it.