RE: [ROOT] compiled namespace sometimes not accessable in rint

From: Philippe Canal (pcanal@fnal.gov)
Date: Sun May 25 2003 - 23:08:58 MEST


Hi Micha,

This does sound wrong and I will check into when I get back to Chicago.
However you may be able to get it work better.

When you create and load the dictionary for anything (classes, functions,
namespaces, ...), the simple fact of loading the dictionary also serves as a
declaration (as far as the interpreter is concerned).  Your script.C reads:

{
#ifndef __my_ns__
#include "my_ns.h"
#endif
    my_ns::say_hello();
}

while the following is sufficient:

{
    my_ns::say_hello();
}

The inclusion of the header __should__ have been harmless (but obviously is
not :) ), so I'll look into that.

Cheers,
Philippe


-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Micha D. Niskin
Sent: Sunday, May 25, 2003 12:28 PM
To: roottalk@cern.ch
Subject: [ROOT] compiled namespace sometimes not accessable in rint


Hello,

	Thank you for your assistance. I have a problem which has me puzzled. I am
using root version 3.05/05 on RedHat 9/i386/gcc-3.2.2. When I compile the
sources below and run 'myroot' I am able to access the function in 'my_ns'
namespace just fine. If I start up 'myroot' and try to immediately execute
'script.C' I get the following error:

      root [0] .x script.C
      Error: say_hello() header declared but not defined FILE:script.C
LINE:8
      *** Interpreter error recovered ***
      root [1] my_ns::say_hello()
      Error: say_hello() header declared but not defined FILE:(tmpfile)
LINE:1
      *** Interpreter error recovered ***

However, if I start 'myroot' and do this instead everything is fine:

      root[0] my_ns::say_hello()
      hello
      root[1] .x script.C
      hello
      root[2] my_ns::say_hello()
      hello

I do not understand what is happening here. Below are the relevant files
(also
a tarball attachment):

//---------------------------my_ns.h
#ifndef __my_ns__
#define __my_ns__
namespace my_ns {
    void    say_hello();
};
#endif



//---------------------------my_ns.C
#include <iostream.h>
#include "my_ns.h"
void my_ns::say_hello() { cout << "hello" << endl; }



//---------------------------main.C
#include <TROOT.h>
#include <TRint.h>
int main(int argc, char **argv)
{
    // Create interactive interface
    TRint *theApp = new TRint("ROOT example", &argc, argv, NULL, 0);

    // Run interactive interface
    theApp->Run();

    return(0);
}



//---------------------------my_nsLinkDef.h
#ifdef __MAKECINT__
#pragma link off all functions;
#pragma link off all globals;
#pragma link off all classes;
#pragma link C++ nestedclass;
#pragma link C++ nestedtypedef;
#pragma link C++ namespace my_ns;
#pragma link C++ function my_ns::say_hello;
#endif



//---------------------------script.C
{
#ifndef __my_ns__
#include "my_ns.h"
#endif
    my_ns::say_hello();
}



##---------------------------Makefile
ARCH          = $(shell root-config --arch)

CXX           =
ObjSuf        = o
SrcSuf        = cxx
ExeSuf        =
DllSuf        = so
OutPutOpt     = -o # keep whitespace after "-o"

ROOTCFLAGS   := $(shell root-config --cflags)
ROOTLIBS     := $(shell root-config --libs)
ROOTGLIBS    := $(shell root-config --glibs)

ifeq ($(ARCH),linux)
# Linux with egcs, gcc 2.9x, gcc 3.x (>= RedHat 5.2)
CXX           = g++
CXXFLAGS      = -O -Wall -fPIC
LD            = g++
LDFLAGS       = -O
SOFLAGS       = -shared
endif

CXXFLAGS     += $(ROOTCFLAGS) -Wno-deprecated
LIBS          = $(ROOTLIBS) $(SYSLIBS)
GLIBS         = $(ROOTGLIBS) $(SYSLIBS)

###

HDRS        = my_ns.h
SRCS        = main.C my_ns.C
OBJS        = main.o my_ns.o
PROGRAM     = myroot

DICTHDRS        = my_nsDict.h
DICTSRCS        = my_nsDict.C
DICTOBJS        = my_nsDict.o

all:    $(PROGRAM)

$(PROGRAM): $(OBJS) $(DICTOBJS)
    @echo "Linking $(PROGRAM)..."
    @/bin/rm -f $(PROGRAM)
    @$(LD) $(LDFLAGS) $(OBJS) $(DICTOBJS) $(ROOTLIBS) -o $(PROGRAM)
    @chmod 555 $(PROGRAM)
    @echo "done"

###

my_ns.o: my_ns.h

my_nsDict.C: my_ns.h
    @echo "Generating dictionary..."
    @rootcint my_nsDict.C -c my_ns.h my_nsLinkDef.h
    @echo "done"

Thanks,
--

Regards,
Micha D. Niskin <mniskin@yahoo.com>




#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################

#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET