I am trying to use CMake to compile a simple gui. The program compiles and links, then fails at run time. Makefile and files posted below. Thank you in advance!
CMakeLists.txt:
cmake_minimum_required(VERSION 3.16...3.27)
set(name gui)
project(${name} CXX)
find_package(ROOT REQUIRED COMPONENTS RIO Physics Core Gui)
message(STATUS "ROOT ${ROOT_VERSION} found at ${ROOT_BINDIR}")
include_directories(./include /usr/local/root/include/)
add_executable(${name} ${name}.cc MainWindow.cc)
target_link_libraries(${name} ROOT::RIO ROOT::Physics ROOT::Core ROOT::Gui)
target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
ROOT_GENERATE_DICTIONARY(${name}_dict MainWindow.hh LINKDEF RootLinkDef.h MODULE ${name})
MainWindow.cc:
// C++
#include "MainWindow.hh"
#include <iostream>
using namespace::std;
MainWindow::MainWindow()
{
Resize(100, 100);
Connect("CloseWindow()", "MainWindow", this, "HandleDisconnectAndTerminate()");
MapSubwindows();
MapWindow();
}
MainWindow::~MainWindow()
{
}
void MainWindow::HandleDisconnectAndTerminate()
{
cout << "it worked!" << endl;
gApplication->Terminate();
}
MainWindow.hh:
#ifndef __MainWindow_hh__
#define __MainWindow_hh__ 1
#include <TColor.h>
#include <TGButton.h>
#include <TObject.h>
#include <TApplication.h>
using namespace std;
class MainWindow : public TGMainFrame
{
public:
MainWindow();
~MainWindow();
void HandleDisconnectAndTerminate();
private:
ClassDef(MainWindow, 1);
};
#endif
gui.cc:
// ROOT
#include <TApplication.h>
// C++
#include <iostream>
#include <string>
using namespace std;
// Custom Classes
#include "MainWindow.hh"
Int_t main(Int_t argc, char **argv)
{
// Run ROOT in standalone mode
TApplication *theapp = new TApplication("gui", &argc, argv);
MainWindow *mainWindow = new MainWindow();
// Run the standalone application
theapp->Run();
// Garbage collection ..
delete mainWindow;
delete theapp;
return 0;
}
RootLinkDef.h:
#ifdef __CINT__
// classes
#pragma link C++ class MainWindow+;
#endif
_ROOT Version: 6.32.00, built for linuxx8664gcc
_Platform: Ubuntu 22.04.4 LTS
_Compiler: g++