Hello
I am trying to use cling to compile some classes which have an extern global variable inside declared as:
extern Globals *gl ;
The Globals class compiles and I can instantiate:
root[2] .L Globals.cpp++
root[3] Globals *gl=new Globals(“MyGlobalFile.conf”)
I fail to compile classes with “extern Globals *gl;” line inside
.L MyLib.cpp++
[… some warnings ….]
cling::DynamicLibraryManager::loadLibrary(): /home/ssd/apps/TRICS/devel/TWaveform_cpp.so: undefined symbol: gl
Any idea how I could solve it? Thank you
Please read tips for efficient and successful posting and posting code
_ROOT Version:6.16.00
_Platform:Ubuntu 16.04
_Compiler: gcc 5.4.0
The keyword extern
means that we declare a variable which will be provided by another translation unit. This means that somewhere in a cpp file you should have the definition gl
somewhere (like static Globals *gl`). Maybe if you reverse root[2] and root[3] it would work.
1 Like
mfg
July 20, 2020, 8:18pm
3
Thank you! Your answer gave me the right hint. I solved it like this:
Created simple cpp program where I define the external variable “gl”, like this:
#include "Globals.h"
Globals *gl ;
void LoadGlobals( TString fTRICS ) {
gl = new Globals( fTRICS ) ;
}
Then I compile it like:
.L Globals.cpp++
.L LoadGlobals.cpp++
LoadGlobals( TString(“Config.file”) )
I compile (with .L xxx.cpp++) all the other libs that use gl
Thank you very much for your help @vvassilev
Glad to hear you solved your issue!