On Linux I have the following tiny ROOT 6 project which has all the features I need to build out what I’m after.
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project (TestRoot CXX)
find_package(ROOT REQUIRED COMPONENTS RIO Core Gpad Gui)
include(${ROOT_USE_FILE})
set(CMAKE_CXX_FLAGS "${ROOT_CXX_FLAGS}")
include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
set(SOURCES main.cpp MainFrame.hpp MainFrame.cpp)
ROOT_GENERATE_DICTIONARY(MainFrame_dict MainFrame.hpp LINKDEF LinkDef.h)
add_executable(TestRoot ${SOURCES} MainFrame_dict.cxx)
set_target_properties(TestRoot PROPERTIES ENABLE_EXPORTS 1)
target_link_libraries(TestRoot ROOT::RIO ROOT::Core ROOT::Gpad ROOT::Gui)
main.cpp
#include <TApplication.h>
#include "MainFrame.hpp"
#include <iostream>
int main(int argc, char* argv[]) {
TApplication theApp("App", &argc, argv);
MainFrame frame(gClient->GetRoot(), 600, 600);
theApp.Run(true);
return 0;
}
MainFrame.cpp
#include "MainFrame.hpp"
#include <TApplication.h>
#include "TGFrame.h"
#include <TGButton.h>
void MainFrame::Press() {
button->SetText("Pressed");
}
MainFrame::MainFrame(const TGWindow* p, unsigned w, unsigned h) : TGMainFrame(p, w, h) {
button = new TGTextButton(this, "Unpressed");
button->Connect("Clicked()", "MainFrame", this, "Press()");
this->AddFrame(button, nullptr);
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
}
MainFrame.hpp
#include <TGFrame.h>
class MainFrame : public TGMainFrame {
public:
MainFrame(const TGWindow* p, unsigned w, unsigned h);
void Press();
TGTextButton* button;
ClassDef(MainFrame, 0);
};
Running cmake . && cmake --build .
in Windows also compiles and builds fine (but seems to produce a lot of new files including an executable in the ‘Debug’ folder (which runs but abort()
s), and a .sln Visual Studio solution which if I run produces the runtime error Unhandled exception at 0x00007FFDA4B3536C in TestRoot.exe: Microsoft C++ exception: std::length_error at memory location 0x0000005CB374F8F0.
at line TROOT::RegisterModule("libMainFrame_dict",
in MainFrameDict.cxx
That’s as far as I have been able to get…
How do I get my simple ROOT 6 program to run on Windows?
ROOT Version: 6.28.04
Platform: Windows
Compiler: MSVC 10.0.19041.0