Root_generate_dictionary

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++


Welcome to the ROOT forum

I think @bellenot can help you.

This CMakeLists.txt works for me (on Windows, but it shouldn’t matter)

cmake_minimum_required(VERSION 3.16...3.27)

set(name gui)
project(${name} CXX)

find_package(ROOT REQUIRED COMPONENTS RIO Physics Core Gui)
include(${ROOT_USE_FILE})
link_directories(${ROOT_LIBRARY_DIR})
message(STATUS "ROOT ${ROOT_VERSION} found at ${ROOT_BINDIR}")
add_executable(${name} ${name}.cc MainWindow.cc)
set_property(TARGET ${name} PROPERTY ENABLE_EXPORTS 1)
if(MSVC)
  set_target_properties(${name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
target_link_libraries(${name} ROOT::RIO ROOT::Physics ROOT::Core ROOT::Gui)
target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${ROOT_INCLUDE_DIRS})
ROOT_GENERATE_DICTIONARY(${name}_dict MainWindow.hh LINKDEF RootLinkDef.h MODULE ${name})

And BTW, it should be ClassDef(MainWindow, 0);

Mine compiles and links. When I go to run the executable I get:

IncrementalExecutor::executeFunction: symbol '_ZN10MainWindow28HandleDisconnectAndTerminateEv' unresolved while linking symbol '__cf_2'!
You are probably missing the definition of MainWindow::HandleDisconnectAndTerminate()
Maybe you need to load the corresponding shared library?
Error in \<TClingCallFunc::make_wrapper\>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) __attribute__((annotate("__cling__ptrcheck(off)")))
extern "C" void __cf_2(void* obj, int nargs, void** args, void* ret)
{
   ((MainWindow*)obj)->HandleDisconnectAndTerminate();
   return;
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::Exec(address, interpVal)>: Called with no wrapper, not implemented!

When I look at the symbols with:

readelf -s --wide gui | grep HandleDisconnectAndTerminate

I get:

FUNC    GLOBAL DEFAULT   16 _ZN10MainWindow28HandleDisconnectAndTerminateEv

Did you try with my version of CMakeLists.txt? Because the error you get is the same I had before using

set_property(TARGET ${name} PROPERTY ENABLE_EXPORTS 1)

And BTW, please read Posting code? Read this first!

Hi Bertrand,

I did not see that line. It works! Thank you so much for your help!

1 Like