I am trying to use CERN's ROOT framework inside a Visual C project.
I built it from sources using the following commands (https://root.cern/releases/release-62606/):
``
cmake -G"Visual Studio 17 2022" -A x64 -Thost=x64 -DCMAKE_INSTALL_PREFIX=..\install_dir ..\root_src
cmake --build . --config Debug --target install
git clone --branch latest-stable --depth=1 https://github.com/root-project/root.git root_src
I then tried to build an example to test if my setup worked.
#include "TF1.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
int main(int argc, char** argv)
{
TApplication app("app", &argc, argv); // Seg fault happens with this line
TCanvas* c = new TCanvas("c", "Something", 0, 0, 800, 600);
TF1* f1 = new TF1("f1", "sin(x)", -5, 5);
f1->SetLineColor(kBlue 1);
f1->SetTitle("My graph;x; sin(x)");
f1->Draw();
c->Modified(); c->Update();
TRootCanvas* rc = (TRootCanvas*)c->GetCanvasImp();
rc->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
app.Run();
return 0;
}
When I build this code and run it, I get a segmentation fault.
Critical error detected c0000374
Exception thrown at 0x00007FFF29FEF609 (ntdll.dll) in RootTest.exe: 0xC0000374: Un segment de mémoire a été endommagé (parameters: 0x00007FFF2A0597F0).
Unhandled exception at 0x00007FFF29FEF609 (ntdll.dll) in RootTest.exe: 0xC0000374: Un segment de mémoire a été endommagé (parameters: 0x00007FFF2A0597F0).
Exception thrown at 0x00007FFF29F0EC5C (ntdll.dll) in RootTest.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
Unhandled exception at 0x00007FFF29F0EC5C (ntdll.dll) in RootTest.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
Exception thrown at 0x00007FFF29F0EC5C (ntdll.dll) in RootTest.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
Unhandled exception at 0x00007FFF29F0EC5C (ntdll.dll) in RootTest.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
Exception thrown at 0x00007FFF29F0EC5C (ntdll.dll) in RootTest.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
Unhandled exception at 0x00007FFF29F0EC5C (ntdll.dll) in RootTest.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
Exception thrown at 0x00007FFF29F0EC5C (ntdll.dll) in RootTest.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
The program '[28120] RootTest.exe' has exited with code 0 (0x0).
Visual Studio tells me that the error comes from TWinNTSystem.cxx
line 1017
while (buf[0] && GetFileAttributes(check_path.Data()) == INVALID_FILE_ATTRIBUTES) {
I use /sdl-
, /permissive
and /std=c 17
.
Do you have any idea why I am having this segmentation fault ?
CodePudding user response:
%ROOTSYS%
must be set else ROOT won't be able to find %ROOTSYS/etc
directory.
This can be achieved by running thisroot.bat
.