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

From: Will Morrison <wzmorrison_at_gmail.com>
Date: Thu, 18 Jun 2009 15:00:40 -0400


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 Thu Jun 18 2009 - 21:00:45 CEST

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