[ROOT] ROOT 2.23.12: Accessing functions in a namespace from a shared library

From: Matthew D. Langston (langston@SLAC.stanford.edu)
Date: Mon Apr 03 2000 - 19:49:01 MEST


How do I export a function, which is nested in a namespace, from a
shared library so that it is available from the CINT interpreter?

Here is a concrete example of the function that I am trying to export
from a shared library to CINT.  The function, named "cross_section" (see
below), is nested inside of multiple namespaces.  Here is the contents
of the header file which declares "cross_section":

  // cross_section.hxx
  namespace MDL
  {
     namespace WAB
     {
        double cross_section( double* variables, double* parameters );
     }
  }


Finally, here is the relevant part of the LinkDef.h file that I am
trying to use to export "cross_section" from the shared library to the
CINT interpreter:


  // LinkDef.h
  #pragma link C++ function MDL::WAB::cross_section;


This doesn't work, as evidenced by the following error message when I
try to run rootcint on these two files:


  $ rootcint -f cross_sectionDict.cxx -c cross_section.hxx LinkDef.h
  Note: link requested for unknown function MDL::WAB::cross_section
FILE:LinkDef.h LINE:21


The pragma that I used (above) was the most straightforward method I
could think of to export the function "cross_section".  Since it didn't
work, I also tried various combinations of the pragmas documented in the
CINT Reference Manual (see http://root.cern.ch/root/Cint.phtml?ref and
search for "#pragma").  In particular, I tried various combinations of
the following two pragmas that seemed to have something to do with
namespaces:


  #pragma link [C|C++|off] [class|struct|union|enum|namespace] [name];
  #pragma link [C|C++|off] defined_in [class/struct/namespace name];


However, I could find no documentation on how to use these two specific
pragmas.  Would someone knowledgeable please instruct us in the use of
these two pragmas?  Would the use of some combination of these two
pragmas solve my problem with exporting the "cross_section" function
from a shared library to the CINT interpreter?

I have attached both of the files "cross_section.hxx" and "LinkDef.h" in
their entirety to this e-mail so that others could try and run the
command

  $ rootcint -f cross_sectionDict.cxx -c cross_section.hxx LinkDef.h

on them.  Please let us know if you can find the correct combination of
the CINT pragmas that allow rootcint to run properly on these two files.
Thank you.


--
Matthew D. Langston
SLD, Stanford Linear Accelerator Center
langston@SLAC.Stanford.EDU

#ifndef MDL_WAB_CROSS_SECTION
#define MDL_WAB_CROSS_SECTION


namespace MDL
{
   namespace WAB
   {
      double cross_section( double* variables, double* parameters );
   }
}


#endif // MDL_WAB_CROSS_SECTION


// -*- c++ -*-

#ifndef MDL_WAB_LINKDEF
#define MDL_WAB_LINKDEF

#ifdef __MAKECINT__

#ifndef G__CROSS_SECTION_DLL
#define G__CROSS_SECTION_DLL
#endif

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ nestedtypedef;
#pragma link C++ nestedclass;

#pragma link C++ global G__CROSS_SECTION_DLL;

#pragma link C++ function MDL::WAB::cross_section;

#endif // __MAKECINT__

#endif // MDL_WAB_LINKDEF



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:22 MET