Testing problem using visual studio 2010 plus ROOT v5.34.36

Hi, everyone,
Any one could run the following example successfully in window OS?
firstly, install https://root.cern.ch/content/release-53436/root_v5.34.36.win32.vc10.debug.zip

(1) start visual studio 2010, then create a regular and empty c++ project (project name “test”) using ROOT histogram class (TH1F).
(2) add a c++ file, “main.cpp”, for example,

#include \<iostream>
#include "TH1F.h"
int main(void)
{
	std::cout<<"hello, world"<<std::endl;
	TH1F* h1 = new TH1F("h1", "h1", 20, 0, 20);
	h1->Draw();
	system("pause");
	return 0;
}

after succesful compile and link, run this project, we have
" an unhandled exception at 0x0f58f50c (libCore.dll) in test4.exe: 0xC0000005: An access violation occurred while reading location 0x00000000"

What happened? Thanks for your answers.

Hi,

First, you should create a TApplication instance:

#include <iostream>
#include "TApplication.h"
#include "TH1F.h"

int main(int argc, char **argv)
{
   TApplication myApp("myapp", &argc, argv);
   std::cout<<"hello, world"<<std::endl;
   TH1F* h1 = new TH1F("h1", "h1", 20, 0, 20);
   h1->Draw();
   myApp.Run(kTRUE);
   system("pause");
   return 0;
}

Then, could you try to build from the Visual Studio command prompt:

cl -nologo -MDd -GR -EHsc main.cpp -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libCint.lib libGui.lib libGpad.lib libHist.lib

I don’t have any Visual Studio 2010 since quite some time, but there should be no problem, as long as you build with the same compiler/linker flags than ROOT itself…

Cheers, Bertrand.

Thank you very much.
Now it works.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.