Compiled shared library doesn't catch changes made in CINT

Hello, experts:

I have a compiled shared library [libinsert.so] which includes a header file [calo.h]. When I load the shared library and include the header file in CINT, and made changes to a variable in the header file, the print function in the shared library doesn’t catch the change. Here is the smallest
script I created.
calo.h (130 Bytes)
insert.C (146 Bytes)
insert.h (53 Bytes)

I compiled it with the following command

g++ -std=c++11  -fPIC --shared -o libinsert.so insert.C

And execute following commands in CINT

gSystem->Load("libinsert.so")
#include "calo.h"
#include "insert.h"
insert()
calo::setnUnits(3)
insert()           // expect 3 here, but get 0

Any walk around for this? Thank you in advance.

ROOT Version: 6.28/06
Platform: Ubuntu 22.04
Compiler: gcc 11.4.0


Why not using a class instead ?

couet@imaccouet Downloads % root
root [0] #include "calo.h"
root [1] calo c
root [2] c.getnUnits()
(int) 0
root [3] c.setnUnits(3)
root [4] c.getnUnits()
(int) 3
root [5] 

calo.h :

#ifndef __CALO__
#define __CALO__


class calo {

private:
    int nUnits = 0;
public:
    calo() {nUnits = 0;}
    void setnUnits (int n) { nUnits = n;}
    int  getnUnits () { return nUnits;}
};

#endif

@weibin It’s not CINT anymore. It’s Cling now.
Use ROOT 6.26 (the bug has been introduced in ROOT 6.28).

1 Like

Unfortunately, class also doesn’t work. The problem is not the calo.h itself. The problem is the insert.C. When compiled, looks like it keeps a local version of calo.h in the shared library, which makes it fail to catch the changes made in CLING.

Ok, thank you.

Thanks for the report. The bug is now being tracked here: Merging issue with global variables between compiled and interpreted code · Issue #15938 · root-project/root · GitHub

@ferhue I assume that if a “global variable” is defined in a “named namespace” then its value should be “shared”. But, if it is defined in an “unnamed namespace”, then it should be “local” (“static”) to every unit that includes the file with its definition. Maybe one should check what the current C++ standard says about it.

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