Mu2e Home
Dynamic Libraries
Search
Mu2e@Work

The attached tar file holds a simple example program that attaches to a dynamic library, makes an instance of one of the classes found in that libary and uses that class. This is an example of what happens behind the scenes with the _plugin mechanism used by the framework.

To build and execute the example, copy the tar file to your own computer then issue the commands:

> tar xzf dynamic.tgz
> cd dynamic
> make
> ./main
This worked for me using SLF 4.6 on both 32 bit and 64 bit hardware. The output should be:
You are in the begining of main
Constructor :: Base
Constructor :: Derived
Creating new object from library
Constructor :: Base
Constructor :: Derived
Derived class function
You are in the end of main
Destructor :: Derived
Destructor :: Base
Destructor :: Derived
Destructor :: Base
So far there is no real documentation for this example. The basic steps found in the main program are:
  1. Open the library libmy.so
  2. Extract from the library a pointer to a function that can return an auto_ptr to an instance of the class. This function is named libFunc.
  3. Call the function in order to get an instance of NewClass.
  4. Call the doStuff method of the object that I just made.
Note that the libFunc function returns an auto_ptr<> to the derived class but that the main program uses this as an auto_ptr<> to base. In this way the framework can manipulate all of the distinct modules via pointer to base. Therefore the Framework never needs to know much about the concrete classes that it can load via plugins; it only needs to know that each of them implements the interface defined by the base class.


Fermilab at Work ]  [ Mu2e Home ]  [ Mu2e @ Work ]  [ Mu2e DocDB ]  [ Mu2e Search ]

For web related questions: Mu2eWebMaster@fnal.gov.
For content related questions: kutschke@fnal.gov
This file last modified Thursday, 11-Feb-2010 00:08:27 CST
Security, Privacy, Legal Fermi National Accelerator Laboratory