Re: How to...

Robert Casties (casties@i0103.desy.de)
Fri, 27 Feb 1998 18:16:47 +0100


[Posted and mailed]

In article <34F6BE78.19188CE0@cern.ch>,
Fons Rademakers <Fons.Rademakers@cern.ch> writes:
[...]
> to make a compiled global visibile from the interpreter add:
>
> #pragma link C++ global gHades;
>
> in your LinkDef.h file. See also:

You will also have to trick the linker when trying to compile this into a
shared library to be used in cint.

Usually you have two object files, one from the dictionary generated by
rootcint xxxdict.C and your code xxx.C which both include the global
variable declaration in your header file xxx.h. The linker then complains
about this doubly defined object (this is fine with classes and
functions).

So you have to change your header file to declare your global variable as
external when included from one of the header files (but not both!).

I used:

<xxx.h>:
//
// some globals
//
#ifndef __noglobals__
Int_t gNevent = 0; // number of events to process (0=all)
#else
extern Int_t gNevent;
#endif

<xxx.C>:
#define __noglobals__
#include "xxx.h"

So xxxdict.o (wich by default includes your header file) declares the
globals and xxx.o uses them.

Cheers
Robert