Load libraries with command line / python

Dear mac rooters,

I am having trouble loading the libraries with python code. Ideally I want to do this:

gROOT.ProcessLine('.L /Users/Liby/work/tau_analysis/FCNC/v05/FCNC-analysis/lib/libAtlasStyle.so')
SetAtlasStyle()

However I got an error saying the “SetAtlasStyle” is not defined. But this problem doesn’t occur when I try with c++ and makefile to load the “libAtlasStyle.so”.
AtlasStyle.C:

void SetAtlasStyle ()
{
  static TStyle* atlasStyle = 0;
  std::cout << "\nApplying ATLAS style settings...\n" << std::endl ;
  if ( atlasStyle==0 ) atlasStyle = AtlasStyle();
  gROOT->SetStyle("ATLAS");
  gROOT->ForceStyle();
}

AtlasStyle.h:

void SetAtlasStyle ()

So I tried to to load the lib with command line, simply do:

root [0] .L lib/libAtlasStyle.so 
root [1] SetAtlasStyle()
Error: Function SetAtlasStyle() is not defined in current scope  (tmpfile):1:
*** Interpreter error recovered ***

I have tried other libraries I built but none of them works.

But when I tried to load libDelphes.so, everything was fine.

Was I doing something wrong while compiling?

Thanks in advance.

Boyang Li


_ROOT Version:v5.34.32
_Platform:MacOSX
Compiler: Not Provided


1 Like

Dear Boyang Li,

You need to let ROOT know about both the library and the headers.
Can you try with:

 ROOT.gInterpreter.ProcessLine('#include "my_cpp_library.h"')
 ROOT.gSystem.Load('./my_cpp_library.so')

Cheers,
Enric

Dear Enric,
I tried this but it does’t help. It seems the root cannot read the library correctly. The function is not visible:

root [1] gInterpreter->ProcessLine("#include \"/Users/Liby/work/tau_analysis/FCNC/v05/FCNC-analysis/include/atlasstyle/AtlasStyle.h\"")
(Long_t)0
root [2] gSystem.Load("/Users/Liby/work/tau_analysis/FCNC/v05/FCNC-analysis/lib/libAtlasStyle.so")
(int)0
root [3] SetAtlasStyle()
Error: SetAtlasStyle() declared but not defined (tmpfile):1:

I started to suspect if the function is in the lib but it’s definitely there:

00000000000029a0 t __ZThn48_NK7TCanvas3IsAEv
0000000000008078 b __ZZ13SetAtlasStylevE10atlasStyle
                 U __ZdlPv

Also the -lAtlasStyle in the makefile works perfectly.

Thanks,
Boyang

Did gSystem->Load actually run? It says it does not have the definition of the method. In your example from the ROOT prompt, you do gSystem.Load, is this a typo (the dot instead of the arrow)?

What happens if you try from Python?

Yes it did. You can see the return value is (int)0 which means the lib is loaded successfully.
I tried python as well, but I got this error instead:

Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for TInterpreterWrapper!

Here is my code:

import sys
from ROOT import *
ROOT.gInterpreter.ProcessLine('#include "/Users/Liby/work/tau_analysis/FCNC/v05/FCNC-analysis/include/atlasstyle/AtlasStyle.h"')
ROOT.gSystem.Load('/Users/Liby/work/tau_analysis/FCNC/v05/FCNC-analysis/lib/libAtlasStyle.so')
SetAtlasStyle()

Hello,

Any ideas for me please?

Try to reverse the order of actions. First load the shared library and then the #include file.

Is this the only function that you cannot use from the library? Can you try with anything else that is declared in the header and defined in the lib?

I tried to reverse the order. But it didn’t help for either python or ROOT prompt.

Honestly, none of them are available, classes, functions.
And I also tried to load other libs I built, not functioning either.

You do not show how you build this “libAtlasStyle.so” library. The “nm” output that you show (in one of your previous posts) suggests that the “SetAtlasStyle” function was not “exported” (I assume you should see something like “T _Z13SetAtlasStylev”).

Sure, I am pasting related code, thanks.

I also found the symbols are local, so I modified my makefile, now the nm output is:

0000000000003730 T __Z10AtlasStylev
00000000000036a0 T __Z13SetAtlasStylev

But the problem is still there. Root cannot recognise “SetAtlasStyle()”.

ls include/atlasstyle/
AtlasCanvas.h AtlasLabels.h AtlasStyle.h AtlasUtils.h
ls src/atlasstyle/
AtlasCanvas.C AtlasLabels.C AtlasStyle.C AtlasUtils.C

ROOTCFLAGS      := $(shell root-config --cflags) -Iinclude -Iinclude/TtHFitter -Iinclude/fcnc
ROOTLIBS        := $(shell root-config --libs)
ROOTGLIBS       := $(shell root-config --glibs)

EXTRALIBS +=$(ROOTLIBS) -L./lib -lfcnc_include
EXTRALIBS +=$(ROOTGLIBS) -lMinuit -lTMVA -lHistFactory -lRooStats -lRooFit -lRooFitCore

CPPFLAGS += $(ROOTCFLAGS) -g -I.
CPPFLAGS  += -Wno-long-long -w 

FCNCLIB := lib
ATLASOBJS = $(patsubst src/atlasstyle/Atlas%.C,bin/.Atlas%.o,$(wildcard src/atlasstyle/Atlas*.C))
MAKESHARED = clang++ -shared -fPIC -dynamiclib -single_module -O2 -mmacosx-version-min=10.10 -m64 -Wl,-install_name,@rpath/$(patsubst $(FCNCLIB)/%,%,$@)

$(FCNCLIB)/libAtlasStyle.so: $(ATLASOBJS)
	@echo Linking $@
	@$(MAKESHARED) $(CPPFLAGS) $(ROOTGLIBS) -o $@ $(ATLASOBJS)

I do not see anything wrong, @Danilo any idea?

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