ROOT6: Load library and create object in same macro

Hi,

I am trying to load a library (with gSystem->Load()) and then create an object of a class from that library in the same macro. It does not work; I am getting linker errors.

The problem is described here: indico.cern.ch/event/279723/ses … ides/1.pdf (slide 4)

The workaround described there works (load in load.C, create object in useClass.C, and run these macros from run.C). However, the slide says that this has been fixed.

I am confused. I am using CMSSW_7_5_0_pre1 with ROOT 6.02/05.

Does anyone know how to make this work from the same macro? The workaround is sort of cumbersome, especially if you have many macros.

Thanks!
Peter

Hi Peter,

for v6.02 you have two options: create a rootmap file for the library to be loaded or use the following construct:

namespace {
  int loadMyLibraryTriggerFunc() {
    gSystem->Load("myLibrary");
    return 0;
  }
  int loadMyLibraryTrigger = loadMyLibraryTriggerFunc();
}

in the global scope (i.e. not inside a function).

In the master (future 6.04) we have improved this considerably; there you can just put R__LOAD_LIBRARY(myLibrary) somewhere next to the #includes.

Cheers, Axel.

Works perfectly. Thanks!