Globals vs. compiled library

Hello ROOTers,

I would like to use global variables from interpreted script in compiled library loaded in the same script.

I have a macro, which loads compiled library. Both, this macro and the library, uses global variables defined in independent header file. In the interpreted macro I do following steps:

  • include the header file
  • load the library by gROOT->LoadMacro(“library.cxx+”) or gSystem->Load(“library”)
  • set values to global variables defined in header file

Than I use function from the library and everything is fine (it sees globals with correct values).

In next step I do change values of global variables again (without exiting CINT interpreted macro) and run function from the library again. And here the function still uses old values of global variables form first setting.

The library is loaded before first setting and so I do not understand, why it accepts setting global variables only once.

I do prefer to not compile the whole macro.

Thank you for any help!

Hi,

Do not include Both the header file and the library. Aka

[quote]- load the library by gROOT->LoadMacro(“library.cxx+”) or gSystem->Load(“library”)

  • set values to global variables defined in header file [/quote]is all you need.

In your example, there is 2 instance of the global variable (one interpreted and the other compiled and CINT only talk to the first one).

Cheers,
Philippe