How to use the objects in the library that is loaded with gSystem with g++ compiler

Dear experts,

I am a CMS student. I have a question about how to use the objects/classes that are defined in a library “libCondFormatsJetMETObjects.so” if I want to compile the code into an executable using g++. So far the code cannot be compiled because the compiler has no idea about the classes that are defined in the library.

The class I would like to use is called “JetCorrectorParameters”. I have a very simple testing code:

#include "TROOT.h"
#include "TSystem.h"
#include <iostream>
int main() {
    std::cout << gSystem->Load("libCondFormatsJetMETObjects.so") << std::endl; // returns 1
    std::cout << gROOT->GetClass("JetCorrectorParameters") << std::endl; // returns 0x4de5b20
    JetCorrectorParameters par = JetCorrectorParameters("Summer19UL18_V5_MC_Uncertainty_AK4PFchs.txt","Total");
    par.printScreen();
    return 0;
}

And I compile the code with

g++ -Wall `root-config --cflags --libs` test.C /<PathToLib>/libCondFormatsJetMETObjects.so -o test

I can feel that it won’t work because the compiler cannot see where the classes are defined. And I would like to know how to make it work with a compiler.

Thank you,
Yao


Please read tips for efficient and successful posting and posting code

_ROOT Version:6.14/09
_Platform:bash shell
_Compiler:g++


I did some search and include the header file that defines the class. (Since it is a cmssw code, I add the corresponding package to local and use the cmssw compiler “scram” to compile the files under CondFormats/)

#include "/CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"

This time, instead of not being able to find the JetCorrectorParameters class, the compiler throws an error that it cannot find the header file (“CondFormats/Serialization/interface/Serializable.h”) that is included in JetCorrectorParameters.h.

Please let me know if I am missing some steps in using the objects in the shared library.

Hi @Yao_Yao ! This probably is better dealt with on the CMS side: I’m sure that CMSSW has a “plan” for how to do this correctly, and there is nothing really specific about ROOT to this. Can you ask them?