Re: cint behaves differently with #ifndef around function definition in header and source files

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Fri, 19 Jun 2009 12:22:15 +0200


Hi Will,

#ifndef __CINT__ really only hides the code from CINT - your compiler will still see it. If the functions definitions are in the headers, your compiler will see them when compiling the dictionary (because they #include these headers). If they reference symbols from boost, these symbols will be missing.

So instead of just hiding them from CINT you want to also hide them when building teh dictionary. Just define your own cpp macro when compiling it, e.g.

   g++ -DDICTIONARY_BUILD -c dict.cxx

and put into your header

#if !defined(__CINT__) && !defined(DICTIONARY_BUILD) //boost functions
#endif

Cheers, Axel.

Will Morrison wrote on 06/18/2009 09:00 PM:
> Hi ROOTers,
>
> I'm currently in the process of integrating root with a previously
> developed software system that uses the boost libraries. Right now, I am
> creating a .so file for a bunch of previously written classes. Boost
> does not work with CINT, so I have placed #ifndef __CINT__ ///boost
> code/// #endif around all the #include's and functions involving
> the boost libaries. However, I have run into a strange problem: if the
> #ifndef statements are placed around function declarations in the
> header, and around the definitions in the source file, everything works
> fine. However, if the function definition is in the .h file and I place
> #ifndef ...... #endif statement around it, an undefined boost related
> symbol ends up in the .so, and root fails to load it. rootcint generates
> the exact same dictionary files in both cases. I'm using version 5.22/00
> Can anybody see why this would happen? Thanks a lot,
>
> Will Morrison
> Boston University
> ANRA http://physics.bu.edu/~ainglis/ANRA/
>
> Here's my example:
> I generate a dictionary, compile and link my class into a library like this:
>
> /home/will/Ana/root/bin/rootcint -f NanaDict.C -c MyClass.h
> g++ -O2 -Wall -fPIC -pthread -m64 -I/home/will/Ana/root/include -c
> NanaDict.C
> g++ -I/home/will/Ana/root/include/ -O0 -g3 -Wall -c -fmessage-length=0
> -fPIC -pthread -m64 -D__CINT__ -MMD -MP -MF"MyClass.d" -MT"MyClass.d"
> -o"MyClass.o" "MyClass.C"
> g++ -m64 -shared -o"libNAnaLib.so" ./MyClass.o NanaDict.o
>
> if the function is declared in MyClass.h and defined in MyClass.C, I can
> load it in to CINT:
> root [0] gSystem->Load("libNAnaLib.so")
> (int)0
> root [1] MyClass *mine = new MyClass()
> root [2] mine->Print()
> OBJ: MyClass MyClass Test class for root library
> root [3] mine->Dump()
> ==> Dumping object at: 0x0000000000b76af0, name=MyClass, class=MyClass
>
> servec ->b76b00 some doubles
> fUniqueID 0 object unique identifier
> fBits 0x03000000 bit field status word
> root [4]
>
> If the function is both declared and defined in MyClass.h:
> root [0] gSystem->Load("libNAnaLib.so")
> dlopen error:
> /home/will/eclipse/workspace/NAnaLib/Debug/./libNAnaLib.so: undefined
> symbol: _ZTIN5boost7archive6detail14basic_iarchiveE
> Load Error: Failed to load Dynamic link library
> /home/will/eclipse/workspace/NAnaLib/Debug/./libNAnaLib.so
> (int)(-1)
> *** Interpreter error recovered ***
> root [1]
>
Received on Fri Jun 19 2009 - 12:23:31 CEST

This archive was generated by hypermail 2.2.0 : Fri Jun 19 2009 - 23:50:02 CEST