Hi, I'm trying to build a shared library to be used by ROOT and I'm having a problem with rootcint processing of #define's. After cutting off the source code almost everything I ended up with the example enclosed below, showing how I failed to make use of #define M_PI 3.14159265358979323846 directive defined in /usr/include/math.h. I'd appreciate if somebody could comment on what's wrong with this example. Thanks, Pasha. -------------------------------------------------------------------------------- There are 3 source files involved: ------------------------------------------------------ LinkDef.h #ifdef __CINT__ #pragma link off all globals; #pragma link off all classes; #pragma link off all functions; #endif ------------------------------------------------------- v23.hh #include "Rtypes.h" #include <math.h> double const PI = M_PI; class V2 { public: double X,Y; V2 (); V2 (double x0, double y0); ClassDef(V2,1) }; #pragma link C++ class V2; -------------------------------------------------------- v23.cc #include "v23.hh" ClassImp(V2) V2::V2 () { X = 0.; Y = 0.; } V2::V2(double x0, double y0) { X = x0; Y = y0; } --------------------------------------------------------- Now I'm trying to build the library: ****************************** pass 1. /cdf/upgrade/tracking/murat/g3/test/glob>rootcint -f v23_cint.cc -c -I../include LinkDef.h v23.hh Error: No symbol M_PI in current scope FILE:v23.hh LINE:5 >>> yes, M_PI is defined in <math.h> via #define, we need to switch ON preprocessing. ***************************** pass 2 Let's do it. First I'm trying to use '#pragma preprocessor on/off. ' So v23.hh becomes: --------------------------------------------------------- v23.hh #include "Rtypes.h" #pragma preprocessor on #include <math.h> double const PI = M_PI; #pragma preprocessor off class V2 { public: double X,Y; V2 (); V2 (double x0, double y0); ClassDef(V2,1) }; #pragma link C++ class V2; --------------------------------------------------------- /cdf/upgrade/tracking/murat/g3/test/glob>rootcint -f v23_cint.cc -c -I../include LinkDef.h v23.hh Error: No symbol M_PI in current scope FILE:v23.hh LINE:6 >>>>>>>>>> so it looks like '#pragma preprocessor on' by itself changes nothing. At ths point I grepp'ed ROOT sourses (development 1.03/01) and it looks like this pragma is not used by ROOT. ****************************** pass 3 Then I notice that CINT (rootcint) has a '-p ' directive, which is said to turn preprocessing ON. /cdf/upgrade/tracking/murat/g3/test/glob>rootcint -f v23_cint.cc -c -p -I../include LinkDef.h v23.hh gcc: v23.hh: linker input file unused since linking not done Note: operator new() masked c >>>>>>>> OK, it looks better, so let's do the next step: /cdf/upgrade/tracking/murat/g3/test/glob>gcc -shared -o v23.so -I$ROOTSYS/include -I../include v23.cc v23_cint.cc -lstdc++ -lm /cdf/upgrade/tracking/murat/g3/test/glob>root No default font loaded ******************************************* * * * W E L C O M E to R O O T * * * * Version 1.02/00 25 July 1997 * * * * You are welcome to visit our Web site * * http://root.cern.ch * * * ******************************************* CINT/ROOT C/C++ Interpreter version 5.13.17, Jul 5 1997 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }. root [0] gSystem->Load("v23.so") Load Error: Dynamic link library /cdf/upgrade/tracking/murat/g3/test/glob/./v23.so can not load (int)(-1) *** Interpreter error recovered *** ******************************************* pass 4 It is clear that in this example <math.h> serves only for demonstration. Lets comment it out, remove '-p' option and see what happens: -------------------------------------------- v23.hh #include "Rtypes.h" #pragma preprocessor on // #include <math.h> // double const PI = M_PI; #pragma preprocessor off class V2 { public: double X,Y; V2 (); V2 (double x0, double y0); ClassDef(V2,1) }; #pragma link C++ class V2; --------------------------------------------- /cdf/upgrade/tracking/murat/g3/test/glob>rootcint -f v23_cint.cc -c -I../include LinkDef.h v23.hh Note: operator new() masked c class V2 in v23.hh line 6 original base of virtual func /cdf/upgrade/tracking/murat/g3/test/glob>gcc -shared -o v23.so -I$ROOTSYS/include -I../include v23.cc v23_cint.cc -lstdc++ -lm /cdf/upgrade/tracking/murat/g3/test/glob>root No default font loaded ******************************************* * * * W E L C O M E to R O O T * * * * Version 1.02/00 25 July 1997 * * * * You are welcome to visit our Web site * * http://root.cern.ch * * * ******************************************* CINT/ROOT C/C++ Interpreter version 5.13.17, Jul 5 1997 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }. root [0] gSystem->Load("v23.so") (int)0 root [1] V2 a(1.,1.) root [2] .p a (class V2)272117632 0x0 double X=1 0x8 double Y=1 0x0 private: static class TClass* fgIsA 0x0 private: long G__virtualinfo -------------------------------------------------------------- now everyting is fine...
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:20 MET