Painting a TCanvas to the screen in a compiled ROOT application

What are the rules for painting to the screen?

My end goal is to put the TCanvas (or TCanvas*) into a class and paint from there, but for now I think that maybe looking at a less complicated example might help. Below is some code that compiles and paints to the screen, on my computer.

# include <TApplication.h>
# include <TCanvas.h>
# include <TH1D.h>
# include <thread>
# include <chrono>

//TCanvas canvas ("fCanvas", "fCanvas", 600, 400);

int main ( int argc, char* argv[] )
    TApplication app ("app",&argc,argv);

    TCanvas canvas ("fCanvas", "fCanvas", 600, 400);
    //TCanvas* canvas = new TCanvas("fCanvas", "fCanvas", 600, 400);

    TH1D h ("h","h",10,0,10);


    std::this_thread::sleep_for( std::chrono::seconds(3) );

    return 0;

You may notice some commented-out lines. If I use either of those definitions of canvas, using the appropriate member access operators on the later-called Update and Draw methods, the application crashes after printing a blank TCanvas-window to the screen. It also crashes if I change app and h to pointers.

If I try to instantiate a class using any sort of ROOT object at all, it crashes the application.

Right now, I’m compiling with MSVC++'s cl.exe and linking with link.exe. I’m working on a 64-bit Windows 7 Enterprise N. I’m trying to port an application that I built in Unix, for which a simple new TApplication("name",0,0); at the start of main made everything work.

So, to reiterate: how can I get my histograms onto the screen in this OS, and maybe others? I doubt that I’ll be able to understand the “why”, but it might be nice to write something about that for others reading this who can. Otherwise, just a step-by-step description of how to use these objects to paint would be wonderful.

Many thanks for any help on this; I’ll gladly provide more information / examples if that should prove useful.

Your little program shows a canvas for me on Mac.

Yes, I’m reasonably sure that it’s a Windows-specific thing. I’m just now compiling my bigger-scale project with a large variety of mysterious compiler options, and it seems to be working so far. See the question “Vector(stl) of TH1F* Objects”.