Canvas not created in compiled code

I am unable to open graphical windows in a compiled application using ROOT libraries. Here is example code:

//test.cc
#include "TCanvas.h"
#include "TH1D.h"

#include <iostream>

void test(void){
    TCanvas* c = new TCanvas("c", "c");
    
    TH1D* hist = new TH1D("hist", "hist", 10, -5.0, 5.0);
    
    hist->Fill(-3);
    hist->Fill(-1);
    hist->Fill(1);
    hist->Fill(3);
    
    hist->Draw("HIST");
}

int main(void){
    test();
    
    // Just here to wait and see if window is being created
    std::string s;
    std::cin >> s;
    
    return 0;
}

This code can be run directly via root test.cc, and produces a simple histogram in its own window. However, when compiled, via g++ test.cc `root-config --cflags --glibs` -o test, and running ./test, no window is created.

Could this be some issue with my build of Root? I did build this myself from source, but didn’t do anything unusual.

ROOT Version: 6.28/10
Platform: Linux
Compiler: g++ 11.4.0

Welcome to the ROOT Forum!
Did you try to search the forum for the same issue? See for example TCanvas doesn't show up - #4 by dastudillo

1 Like

I did a search, but clearly wasn’t using the right keywords. Thanks for the help!

1 Like