Hi,
I have been trying to use ROOT in a CMake project and have come up against an issue. I have a group of custom classes in .cxx files with associated header .h files. Now I want to create a shared dynamic dictionary, that I can then load into my .C root macros to access types and functions within the library without having to recompile the library every time I change something trivial in the root macro (i.e. the color of a histogram).
I’ve been reading up online about how to use CMake to do this, and my understanding is that my CMakeLists file needs to first use root_generate_dictionary to create the dictionary with the header files and the linkdef file, and then add_library (with the SHARED flag) to create the .so file. Then target_link_libraries is used to link the library to ${ROOT_LIBRARIES}.
I’ve followed all of these steps, and have obtained the .so file. However, when I tried to use it in the macro using
gSystem->Load(path/lib.so)
I got a cling dynamic library manager error saying “undefined symbol”. After some digging, I learnt about mangling in c++ and realized the “undefined symbol” being referenced was a mangled function name. I experimented and managed to successfully load the library and even include one of my dictionary header files using
extern "C" {
gSystem->Load(path/lib.so)
#include "path/Name.h"
}
However, now when I try to actually call and initialize an object of the custom type within a void method in the macro, I once again get an error message about a symbol that I believe is coming from this mangling. The error is:
IncrementalExecutor::executeFunction: symbol ‘_ZN16NameC1Ev’ unresolved while linking [cling interface function]!
You are probably missing the definition of Name::Name()
Maybe you need to load the corresponding shared library?
I am now at a loss of how to proceed, and any help would be greatly appreciated. I am very new to CMake and building projects generally, I am going entirely off of the Modern CMake and More Modern CMake tutorials, and the ROOT documentation. Is there an issue in how I am generating the library and dictionary that could avoid it getting mangled in the first place, or is there something further I need to do in the macro to access it? Thanks in advance for the help.
ROOT Version: 6.34
Platform: CentOS8, running ROOT in a Singularity container based on the ROOT docker container
Compiler: CMake