No graphics/canvas windows when using ROOT with VC++7.1


I’m currently using the ROOT libraries as part of a console app on Windows XP, with Visual Studio.NET 2003 as my compiler. I’ve got some code that compiles correctly, and is supposed to display some histograms on the screen as well as saving them to postscript files.

The problem I have is this: The program appears to be running correctly, with the exception that it doesn’t display any of the canvases on the screen. It correctly prints them to the postscript files, so as far as I can tell the progam is running properly in every other respect.

The chunk of code I am using to display the histograms works fine when used in a macro from within CINT, so I am at a bit of a loss to understand why it doesn’t work when I compile the code. For example, this works fine from within CINT:

gammaCanv -> Divide(2,2);
gammaCanv -> cd(1);
gammaCanv -> cd(2);
gammaCanv -> cd(3);
gammaCanv -> cd(4);

I notice from page 6 of the root manual that all of the graphics-dependent libraries that I have included say things like:

“libGpad.lib is the pad and canvas classes which depend on low level graphics”

What are these “low level graphics”, and how do I get them to operate within 2003? Could this be the reason that I am not getting any graphical output from ROOT? I can’t think of anything else that could be causing this problem.

Oh, and i’m using ROOT version 4.04.02

Thanks in advance for any help/insight!


Could you send the shortest possible script reproducing your problem?
When you execute root at the command line, do you see teh splash screen?
When inside root and typing the following command
root > TCanvas c
do you see a graphics window?

In case you see a graphics window with your application, but an empty
canvas, are you sure that your C++ objects are not deleted (going out of scope) when the function returns?


Hi Rob,

Did you link your app with these libraries :


depending of what you need, take a look into $(ROOTSYS)/lib


Hi Rene & Bertrand,

Thanks for your suggestions!

In response to Rene, the object that contains my histograms is defintely not going out of scope, so it is not that. I can’t really offer you a script to reproduce the problem, since i’m not using CINT but am compiling my code. However, the code i’m using to make & display my plots works fine when in a macro, just not when compiled.

In response to Bertrand, I have VC++ 7.1 set up according to Francois-Xavier Gentit’s web site (, and have tried adding the libraries you suggested (I can’t find libfreetype.lib in that directory). It appears to make no difference at all.

Any more suggestions? Do either of you commonly use VC++ 7.1? When you make a Win32 Console App with ROOT libraries, I take it you don’t suffer these problems?



Furthering what i have said, if I have just my main function in my current VC++ setup with:

using std::cout; using std::endl;
#include <conio.h> //for _getch()
#include “TCanvas.h”

int main()
TCanvas c;

cout << “\nPress any key to continue” << endl;
while(!_getch()) {}

return 0;

I still get absolutely no graphics display.


Well, I see. Your code should be like this:

#include "TApplication.h"
#include "TCanvas.h" 

int main(int argc, char *argv[]) 
   TApplication theApp("TestFrame", &argc, argv); 
   TCanvas c; 

   return 0; 

You must create a TApplication in order to have Root processing events ( within theApp.Run() )
Take a look into $(ROOTSYS)/test directory, there are samples. :wink:


Ah brilliant - Thanks for all your help!


Hi Bertrand,

Right, your code makes everything work properly. However, I was presuming that when the user closed all the canvas windows theApp.Run() would then terminate its infinite loop and return control to the console window. It doesn’t do this - is there a way around this? At the moment I have to use ctrl-c to exit the program.



To exit Root, you have to select “Quit Root” from the menu “File” of the canvas.
You can also make your own TCanvas derivated class, and call gApplication->Terminate() in CloseWindow().
Or to manually keep a list of opened canvases, and calling gApplication->Terminate() when count is down to zero.