Compiling and loading macro at runtime

Hi to all,
I have the following problem.

I run from root a program, say analysis.C, by typing .L analysis.C+O; this program requires additional classes that are defined each in a separate file (they are the .class files generated by TMVA training) which stays in another directory.
Since these classes are really big (> 8000 lines of code), it takes a while to compile them all; furthermore, I want the possibility to add a new class without having to recompile all classes.

The simpler way is to load by hand all these classes before loading analysis.C:
.L …/classifiers/class1.C+O
.L …/classifiers/class2.C+O

.L analysis.C+O
This works, but it’s boring to do every time.

Instead, I added these lines into rootlogon.C

   const UInt_t nLIBs = 3;
   Char_t *LibName[nLIBs] = { "BDTG_EN", "BDTG_EN_LNN",
      "BDTG_EN_LNN_E" };

   Char_t path[256];

   for (UInt_t ilib = 0; ilib < nLIBs; ++ilib)
   {
      snprintf(path, 256, "../classifiers/%s_C.so", LibName[ilib]);

      cout << Form(" *** Loading library '%s' ... ", path) << flush;

      Int_t res = gSystem->Load(path);

      switch(res)
      {
         case  0: cout << Form("Library successfully loaded\n"); break;
         case  1: cout << Form("Library already loaded\n"); break;
         case -1:
         {
            cout << Form("Library doesn't exist: compiling library ...\n");
            snprintf(path, 256, "../classifiers/%s.C", LibName[ilib]);
            if (gSystem->CompileMacro(path, "O-", "", "../classifiers/"))
               cout << "   Library compiled and loaded";
            else
               cout <<  " *** ERROR! Library not compiled and not loaded!\n";
            break;
         }
         case -2: cout << Form("Library version mismatch\n"); break;
      }
   }

The first time that I open root, it says that it cannot find the libraries and thus it compiles them, but it doesn’t load the compiled libraries (despite CompileMacro return value is succesfull), since .L analsysis.C+O says that it cannot find some functions that are defined in the just compiled libraries.
I checked and the .so files are correctly generated in the same folder of the classes source code.
Furthermore, if I exit from root, these .so files are deleted (so the next time I open root, it recompiles all classes…), while if I compile and load the classes by hand this doesn’t happens.

What’s wrong with the rootlogon.C code?

Thanks for the help.

Hi,

[quote]The first time that I open root, it says that it cannot find the libraries and thus it compiles them, but it doesn’t load the compiled libraries (despite CompileMacro return value is succesfull)[/quote]This is odd, what does root [] .filesreturns after the rootlogon execution?

Philippe.

Thank you pcanal, I missed the k option in the documentation.
Now it works, after the compilation the library is loaded; I don’t know why before didn’t work.