[ROOT] 2.25.01: revisiting the "function in a namespace" problem

From: Matthew D. Langston (langston@SLAC.stanford.edu)
Date: Thu Aug 17 2000 - 05:52:01 MEST


Hi Masa,

Back in the early part of April you were helping me with the problem of how
to export a function, which is nested in a namespace, from a shared library
so that it is available from the CINT interpreter.

At the time, you said that the problem was fixed in CINT 5.14.26.  However,
the problem still exists in ROOT 2.25.01, which uses CINT 5.14.44.  Did the
namespace support get broken again somehow?

I have attached the two e-mails from our previous discussion to remind you
of what the problem was (it includes an example you can try to test the bug
for yourself).  FYI, all of these e-mails (and others from the thread) are
in roottalk beginning on 2000.04.03 if you need to refer to them for more
detail.

Can you. or another knowledgeable CINT internals expert, help me with this
problem please?  Thank you.

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


attached mail follows:


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

attached mail follows:


Hello Matthew, I can not try it on ROOT because of some reason, but your code works fine on pure cint. After adding definition of cross_section() function, $ makecint -mk makefile -dl cross_section.dll -H cross_exction.hxx LinkDef.h $ make -f makefile $ cint cross_section.dll cint> p MDL::WAB::cross_section(0,0) (double)0.000000 cint> After writting above message, I noticed that you use 5.14.25. 'pragma link C++ namespace' is supported after 5.14.26. No wonder you can not do it. In that case, try '#pragma link C++ class [namespacename];' instead. There is no difference. If this doesn't work either , please download newer version. Thank you Masaharu Goto > >Hi Masaharu, > >I had already tried the two namespace pragmas that you suggested (I >hinted at this in my original e-mail), and they don't work either. So, >the problem/question remains - how do I import a function in a namespace >even though I am already using the two pragmas that you recommend? I >have attached the two files that are necessary to run the following >command, which demonstrates the problem: > > $ rootcint -f cross_sectionDict.cxx -c cross_section.hxx LinkDef.h > >Were you actually able to verify that you can run the above command >without problems? It definitely does not work with ROOT 2.23.12 (which >corresponds to CINT 5.14.25). > >Thank you for your help and expertise. > >



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