What does a minimal Windows 10 project configuration look like?

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


Depending the version of ROOT you are using, here is an example for 64 bit:

cmake -G "Visual Studio 17 2022" -A x64 -Thost=x64 ..\src

then, to build:

cmake --build . --config Release

And in general, don’t build in source, but create a separate build directory

And I would change the CMakeLists.txt as following:

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)
if(MSVC)
  set_target_properties(TestRoot PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
  add_custom_command(TARGET TestRoot POST_BUILD
     COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/TestRoot.exe
                                      ${CMAKE_CURRENT_BINARY_DIR}/TestRoot.exe)
endif()
target_link_libraries(TestRoot ROOT::RIO ROOT::Core ROOT::Gpad ROOT::Gui)

So for reproducibility and avoidance of doubt, I have a folder called testroot containing two folders ‘src’ and ‘build’. I have moved all of my above files into the src folder. I have then modified my CMakeLists.txt file to look as you have described. I installed ROOT by downloading root_v6.28.04.win64.vc17.exe then I navigated to C:/root_v6.28.04/bin and executed thisroot.bat

I then navigated to my testroot/build folder and ran
cmake -G "Visual Studio 17 2022" -A x64 -Thost=x64 ..\src && cmake --build . --config Release

which completed without error.

Clicking on the executable in the build folder gives the two popup errors “The code execution cannot proceed because libCore.dll was not found. Reinstalling the program may fix this problem.”

The code execution cannot proceed because libGui.dll was not found. Reinstalling the program may fix this problem.

Clicking on the Visual Studio solution I get the popup ‘Unable to start program /***/ALL_BUILD. The system cannot find the file specified.’ Deleting the ALL_BUILD, MainFrame_dict and ZERO_CHECK solutions and running this again, I get the libGui.dll runtime error.

I tired adding C:\root_v6.28.04\bin to the PATH environment variable and that didn’t help.

And if you open a command prompt, call C:\root_v6.28.04\bin\thisroot.bat before calling TestRoot.exe, does it work?

Oops I lied! Doing precisely the above from scratch produced an executable in the build folder that works. The TestRoot.sln works if I just switch to Release mode and I imagine I will be able to get Debug mode to work too. Sorry for the confusion and thanks for the help.

Nope, you cannot mix Debug and Release builds. If you need to debug your code, you will most probably have to take the Debug build of ROOT and use the RelWithDebInfo build configuration for your project

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