I have a C++ program which uses ROOT histograms. Output to a ROOT file is OK, but I can’t get any graphical output. Basically, I’ve started by using the “hsimple.C” tutorial which uses a canvas.
When linking with -lPyROOT everything works except this.
My system: Fedora 11, 64bit, root 5.26
NB: I can view the file contents when using root directly.
why do you link against libPyROOT? You should create your own TApplication object. It’s much simpler if you run your code from inside ROOT: .x mycode.C+ with main() renamed to mycode().
I need to run my code as a C++ program, not as a ROOT “script”.
Therefore, running my code from inside ROOT doesn’t help me.
The canvas is created, so I think ROOT must connect to some sort of display unit.
I’ve seen PyQT mentioned somewhere. Is that an option?
That’s a very common mis-perception, I don’t know where it comes from When you run in ROOT with
you run binary code compiled by your system’s compiler - there is nothing like “ROOT script”, MyCode.cxx must be proper and valid C++ that your compiler understands. The major advantage of this approach is that ROOT does the Makefile for you: we know what libraries you need, how to generate dictionaries etc. In the end (if the dependencies tell it to), ROOT invokes rootcint to get the dictionary, the compiler, the linker to get a shared library, and then dlopens that.
Sorry, I’m not convinced yet
[quote=“akugel”]The canvas is created, so I think ROOT must connect to some sort of display unit.
I’ve seen PyQT mentioned somewhere. Is that an option?[/quote]
Hmm, adding complexity is rarely a solution When you say “the canvas is created” you mean the C++ object, not the window in your display manager, correct? That (again) points to libPyROOT. You forgot to tell me why you want to link against it. You should instead create your own TApplication object. Or, really!, simply run .x MyCode.cxx+
I think I understand now how to get this to work, after looking at hworld.C in the test directory. Maybe this kind of usage could be documented a bit more - or maybe I’ve just didn’t look for the wrong keywords.
There’s one issue left: access to ROOT globals like the gStyle pointer. It is also not an element of TApplication. How do I access gStyle?
Thanks for your help.
gStyle is declared in TStyle.h, so you’ll need to #include that. Or did I misunderstand your question?
If you really need the stand-alone binary please use root-config --cflags and root-config --glibs instead of spelling it out; that we we can reshuffle libraries in a new version and your Makefile will still work.
thanks again for the hints. Looks quite good now. I will change the library mapping according to your suggestion.