Standalone C++ program with ROOT classes: Error in <TTree::Bronch>: Cannot find class:CLASSNAME

Hello,

I’m trying to convert ROOT scripts to standalone C++ program. These scripts work fine in ROOT interactive session but C++ program failed with message:

Error in <TTree::Bronch>: Cannot find class:bPEMPos

To begin describe problem with C++ program I need to clarify what I mean “work fine” and the simple task:

  • I made special class to store coordinates (triple of doubles) and id. It is declared in .h file and implemented in .cxx;
  • I compiled it in root interactive session:
      .L geom.cxx++
    
  • I run special script to write data to a file:
      .x write_geom.C
    
  • I checked that written data can be read and are Ok:
      .x read_geom.C
    

These steps work fine in ROOT 6.10/08 on my system (Archlinux x86_64, self-compiled distro package).

Then I made standalone program test_geom.cxx. It compiles fine (make test_geom) but when I run it it segfaults:

Populating 'geometry.root' file:
Error in <TTree::Bronch>: Cannot find class:bPEMPos

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007faedb783e8a in waitpid () from /usr/lib/libc.so.6
#1  0x00007faedb701bcf in do_system () from /usr/lib/libc.so.6
#2  0x00007faedc6481a4 in TUnixSystem::StackTrace() () from /usr/lib/root/libCore.so.6.10
#3  0x00007faedc64a8de in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib/root/libCore.so.6.10
#4  <signal handler called>
#5  0x000055a4db03f7ba in bPEMPos::setData (this=0x0, ID=<incomplete type>, X=0.35355339059327379, Y=0.35355339059327373, Z=0.5) at geom.cxx:11
#6  0x000055a4db03ff69 in write_geom() ()
#7  0x000055a4db0400e4 in main ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x000055a4db03f7ba in bPEMPos::setData (this=0x0, ID=<incomplete type>, X=0.35355339059327379, Y=0.35355339059327373, Z=0.5) at geom.cxx:11
#6  0x000055a4db03ff69 in write_geom() ()
#7  0x000055a4db0400e4 in main ()
===========================================================

I searched the forum and although I found some similar posts don’t get how to solve the problem: I want to use ROOT C++ structures in my C++ program but not to use C++ classes in ROOT. Do I do something fundamentally wrong?

Files can be found here:
https://bitbucket.org/vp1981/root/src/e0582cca683c472ce52e435f8539da1a7de05bcb/misc/?at=default

WBR, Vladimir Lomov

Hi Vladimir,

you are missing the dictionary for your class, which is automatically built by Aclic. This is a very standard procedure.
Just do the following:
bPEMPos.h

<Here your class is defined>

sel.xml

<rootdict>
<class name ="bPEMPos" />
<rootdict>

the command to generate dictionary library

genreflex bPEMPos.h -s sel.xml --rootmap-lib libbPEMPos.so --rootmap libbPEMPos.rootmap
g++ -shared -fPIC -o libbPEMPos.so `root-config --cflags --libs` bPEMPos_rflx.cpp <the other necessary includes>

Make sure to place the shared library and the .pcm file in the LD_LIBRARY_PATH.
Let me know how it goes.

Cheers,
D

Hello D,

thank you for your advice. I must say that I never would figure out what to do (or it would take too long).

Still I got errors on last command, I tested on my Archlinux box, Ubuntu box in VM with box-compiled ROOT and Fedora box in VM with precompiled ROOT (output from Fedora box):

genreflex bPEMPos.h -s bpempos.xml --rootmap-lib libbPEMPos.so --rootmap libbPEMPos.rootmap
g++ -shared -fPIC -std=c++14 -o libbPEMPos.so `root-config --cflags --libs` bPEMPos_rflx.cpp
bPEMPos_rflx.cpp:77:33: error: ISO C++ does not permit 'TObject::fgIsA' to be defined as 'bPEMPos::fgIsA' [-fpermissive]
 atomic_TClass_ptr bPEMPos::fgIsA(0);  // static to hold class pointer
                                 ^
bPEMPos_rflx.cpp:80:33: error: no 'const char* bPEMPos::Class_Name()' member function declared in class 'bPEMPos'
 const char *bPEMPos::Class_Name()
                                 ^
bPEMPos_rflx.cpp:86:35: error: no 'const char* bPEMPos::ImplFileName()' member function declared in class 'bPEMPos'
 const char *bPEMPos::ImplFileName()
                                   ^
bPEMPos_rflx.cpp:92:27: error: no 'int bPEMPos::ImplFileLine()' member function declared in class 'bPEMPos'
 int bPEMPos::ImplFileLine()
                           ^
bPEMPos_rflx.cpp:98:29: error: no 'TClass* bPEMPos::Dictionary()' member function declared in class 'bPEMPos'
 TClass *bPEMPos::Dictionary()
                             ^
bPEMPos_rflx.cpp:105:24: error: no 'TClass* bPEMPos::Class()' member function declared in class 'bPEMPos'
 TClass *bPEMPos::Class()
                        ^
bPEMPos_rflx.cpp:112:37: error: no 'void bPEMPos::Streamer(TBuffer&)' member function declared in class 'bPEMPos'
 void bPEMPos::Streamer(TBuffer &R__b)
                                     ^
make: *** [Makefile:22: libbPEMPos.so] Error 1

This is for gcc, clang gives a bit different messages:

genreflex bPEMPos.h -s bpempos.xml --rootmap-lib libbPEMPos.so --rootmap libbPEMPos.rootmap
clang++ -shared -fPIC -std=c++14 -o libbPEMPos.so `root-config --cflags --libs` bPEMPos_rflx.cpp
bPEMPos_rflx.cpp:77:28: error: no member named 'fgIsA' in 'bPEMPos'
atomic_TClass_ptr bPEMPos::fgIsA(0);  // static to hold class pointer
                  ~~~~~~~~~^
bPEMPos_rflx.cpp:80:22: error: out-of-line definition of 'Class_Name' does not match any declaration in 'bPEMPos'
const char *bPEMPos::Class_Name()
                     ^~~~~~~~~~
bPEMPos_rflx.cpp:86:22: error: out-of-line definition of 'ImplFileName' does not match any declaration in 'bPEMPos'
const char *bPEMPos::ImplFileName()
                     ^~~~~~~~~~~~
bPEMPos_rflx.cpp:92:14: error: out-of-line definition of 'ImplFileLine' does not match any declaration in 'bPEMPos'
int bPEMPos::ImplFileLine()
             ^~~~~~~~~~~~
bPEMPos_rflx.cpp:98:18: error: out-of-line definition of 'Dictionary' does not match any declaration in 'bPEMPos'
TClass *bPEMPos::Dictionary()
                 ^~~~~~~~~~
bPEMPos_rflx.cpp:105:18: error: out-of-line definition of 'Class' does not match any declaration in 'bPEMPos'
TClass *bPEMPos::Class()
                 ^~~~~
bPEMPos_rflx.cpp:112:15: error: out-of-line definition of 'Streamer' does not match any declaration in 'bPEMPos'
void bPEMPos::Streamer(TBuffer &R__b)
              ^~~~~~~~
7 errors generated.
make: *** [Makefile:23: libbPEMPos.so] Error 1

My wild guess: *_rflx.cpp was generated with errors. I found Class_Name in Rtypes.h but including it in bPEMPos.h changes nothing.

Seems I missed something trivial.

P.S. Updated files can be found on this page: https://bitbucket.org/vp1981/root/src/27306a7cd58c8562b774def01af631961fd878ac/misc/?at=default (Sorry, but I only now realize that bitbucket changes URL when I update the repository).


WBR, Vladimir Lomov

Ok, I was able to compile libbPEMPos.so library (I was need to get rid of ifdef guard for ClassDef) but now I get error when linking my test program:

g++ -I/usr/include/root -std=c++14 -L/usr/lib/root -lTree -lRIO -lCore -L. -lbPEMPos -o test_geom test_geom.cxx
./libbPEMPos.so: In function `bPEMPos::bPEMPos()':
/home/vladimir/baikal-gvd/root/bPEMPos.cxx:3: undefined reference to `vtable for bPEMPos'
collect2: error: ld returned 1 exit status
make: *** [Makefile:14: test_geom] Error 1

Some topics on the forum were mentioned LinkDef.h header file with some #pragma's, should I make such file? According to FAQ (https://root.cern.ch/faq/how-generate-dictionary) I need to use rootcling to generate dictionary but I’m using genreflex. I’m a bit lost here, should I use genreflex or should I use rootcling?


WBR, Vladimir Lomov

Sorry,
I have to correct myself. The error message I posted earlier was incomplete (my fault). This is from my Archlinux box:

genreflex bPEMPos.h -s bpempos.xml --rootmap-lib libbPEMPos.so --rootmap libbPEMPos.rootmap
clang++ -shared -fPIC -o libbPEMPos.so `root-config --cflags --libs` bPEMPos_rflx.cpp
clang++ `root-config --cflags --libs` -g -c bPEMPos.cxx -o libbPEMPos.so
clang-5.0: warning: -lCore: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lImt: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lRIO: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lNet: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lHist: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lGraf: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lGraf3d: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lGpad: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lTree: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lTreePlayer: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lRint: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lPostscript: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lMatrix: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lPhysics: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lMathCore: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lThread: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lMultiProc: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -Wl,-rpath,/usr/lib/root: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: -ldl: 'linker' input unused [-Wunused-command-line-argument]
clang-5.0: warning: argument unused during compilation: '-L/usr/lib/root' [-Wunused-command-line-argument]
clang-5.0: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument]
clang++ `root-config --cflags --libs` -std=c++14 -L. -lbPEMPos -o test_geom test_geom.cxx
./libbPEMPos.so: In function `bPEMPos':
/home/vladimir/baikal-gvd/root/bPEMPos.cxx:4: undefined reference to `vtable for bPEMPos'
/tmp/test_geom-65c450.o: In function `int TTree::SetBranchAddress<bPEMPos>(char const*, bPEMPos**, TBranch**)':
test_geom.cxx:(.text._ZN5TTree16SetBranchAddressI7bPEMPosEEiPKcPPT_PP7TBranch[_ZN5TTree16SetBranchAddressI7bPEMPosEEiPKcPPT_PP7TBranch]+0xc): undefined reference to `typeinfo for bPEMPos'
test_geom.cxx:(.text._ZN5TTree16SetBranchAddressI7bPEMPosEEiPKcPPT_PP7TBranch[_ZN5TTree16SetBranchAddressI7bPEMPosEEiPKcPPT_PP7TBranch]+0x58): undefined reference to `typeinfo for bPEMPos'
/tmp/test_geom-65c450.o: In function `TBranch* TTree::Branch<bPEMPos>(char const*, char const*, bPEMPos**, int, int)':
test_geom.cxx:(.text._ZN5TTree6BranchI7bPEMPosEEP7TBranchPKcS5_PPT_ii[_ZN5TTree6BranchI7bPEMPosEEP7TBranchPKcS5_PPT_ii]+0xb): undefined reference to `typeinfo for bPEMPos'
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:13: test_geom] Error 1

and this is from Fedora box (in VM):

genreflex bPEMPos.h -s bpempos.xml --rootmap-lib libbPEMPos.so --rootmap libbPEMPos.rootmap
g++ -shared -fPIC -o libbPEMPos.so `root-config --cflags --libs` bPEMPos_rflx.cpp
g++ `root-config --cflags --libs` -g -c bPEMPos.cxx -o libbPEMPos.so
g++ `root-config --cflags --libs` -L. -lbPEMPos -o test_geom test_geom.cxx
./libbPEMPos.so: In function `bPEMPos::bPEMPos()':
/home/vladimir/tmp/root/bPEMPos.cxx:3: undefined reference to `vtable for bPEMPos'
/tmp/ccBrzNF0.o: In function `int TTree::SetBranchAddress<bPEMPos>(char const*, bPEMPos**, TBranch**)':
test_geom.cxx:(.text._ZN5TTree16SetBranchAddressI7bPEMPosEEiPKcPPT_PP7TBranch[_ZN5TTree16SetBranchAddressI7bPEMPosEEiPKcPPT_PP7TBranch]+0x23): undefined reference to `typeinfo for
 bPEMPos'
test_geom.cxx:(.text._ZN5TTree16SetBranchAddressI7bPEMPosEEiPKcPPT_PP7TBranch[_ZN5TTree16SetBranchAddressI7bPEMPosEEiPKcPPT_PP7TBranch]+0x3f): undefined reference to `typeinfo for
 bPEMPos'
/tmp/ccBrzNF0.o: In function `TBranch* TTree::Branch<bPEMPos>(char const*, char const*, bPEMPos**, int, int)':
test_geom.cxx:(.text._ZN5TTree6BranchI7bPEMPosEEP7TBranchPKcS5_PPT_ii[_ZN5TTree6BranchI7bPEMPosEEP7TBranchPKcS5_PPT_ii]+0x32): undefined reference to `typeinfo for bPEMPos'
collect2: error: ld returned 1 exit status
make: *** [Makefile:13: test_geom] Error 1

I intentionally used different compilers on different boxes to be sure that the error is not related with a compiler.


WBR, Vladimir Lomov

Try:

`root-config --cxx --cflags` -fPIC -shared -o libbPEMPos.so bPEMPos.cxx bPEMPos_rflx.cpp `root-config --libs`
`root-config --cxx --cflags` -o test_geom test_geom.cxx -L. -lbPEMPos `root-config --libs`

Hi Wile_E_Coyote,

thanks, these commands allows to compile both libbPEMPos.so and test_geom without problem (earlier I was able to compile without problem too, so this will help me to understand right sequence for gcc), but now when I run test_geom it segfaults:
(Archlinux box):

Populating 'geometry.root' file:

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007fc2ee229e8a in waitpid () from /usr/lib/libc.so.6
#1  0x00007fc2ee1a7bcf in do_system () from /usr/lib/libc.so.6
#2  0x00007fc2f27886d4 in TUnixSystem::StackTrace() () from /usr/lib/root/libCore.so.6.12
#3  0x00007fc2f278ae7e in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib/root/libCore.so.6.12
#4  <signal handler called>
#5  0x00007fc2f2a495a0 in vtable for TString () from /usr/lib/root/libCore.so.6.12
#6  0x000055d9a6c5fcfc in write_geom() ()
#7  0x000055d9a6c5fdc9 in main ()
===========================================================                                                                                                                       
                                                                                                                                                                                  

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007fc2f2a495a0 in vtable for TString () from /usr/lib/root/libCore.so.6.12
#6  0x000055d9a6c5fcfc in write_geom() ()
#7  0x000055d9a6c5fdc9 in main ()
===========================================================

under gdb:

GNU gdb (GDB) 8.0.1                                                                                                                                                               
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...                                                                                                                   
Reading symbols from ./test_geom...(no debugging symbols found)...done.                                                                                                           
(gdb) run                                                                                                                                                                         
Starting program: /home/vladimir/baikal-gvd/root/test_geom                                                                                                                        
[Thread debugging using libthread_db enabled]                                                                                                                                     
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Populating 'geometry.root' file:                                                                                                                                                  
                                                                                                                                                                                  
Program received signal SIGSEGV, Segmentation fault.                                                                                                                              
0x00007ffff7b7b5a0 in vtable for TString () from /usr/lib/root/libCore.so.6.12                                                                                                    
(gdb) bt                                                                                                                                                                          
#0  0x00007ffff7b7b5a0 in vtable for TString () from /usr/lib/root/libCore.so.6.12                                                                                                
#1  0x0000555555555cfc in write_geom() ()                                                                                                                                         
#2  0x0000555555555dc9 in main () 

On Fedora box (in VM, precomiled ROOT binaries) I don’t get any valuable info just segfault:

Populating 'geometry.root' file:            

 *** Break *** segmentation violation       
 Generating stack trace... 

under gdb:

GNU gdb (GDB) Fedora 8.0.1-33.fc27                                                                                                                                                
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test_geom...(no debugging symbols found)...done.                                                                                                           
(gdb) run                                                                                                                                                                         
Starting program: /home/vladimir/tmp/root/test_geom                                                                                                                               
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.26-16.fc27.x86_64                                                                                                 
[Thread debugging using libthread_db enabled]                                                                                                                                     
Using host libthread_db library "/lib64/libthread_db.so.1".                                                                                                                       
Populating 'geometry.root' file:                                                                                                                                                  
Detaching after fork from child process 28744.                                                                                                                                    
Detaching after fork from child process 28746.                                                                                                                                    
Detaching after fork from child process 28748.                                                                                                                                    
Detaching after fork from child process 28750.                                                                                                                                    
Detaching after fork from child process 28752.                                                                                                                                    
Detaching after fork from child process 28754.                                                                                                                                    
Detaching after fork from child process 28758.                                                                                                                                    
                                                                                                                                                                                  
Program received signal SIGSEGV, Segmentation fault.                                                                                                                              
0x000000000207cdd0 in ?? ()                                                                                                                                                       
Missing separate debuginfos, use: dnf debuginfo-install libcrypt-nss-2.26-16.fc27.x86_64 libgcc-7.2.1-2.fc27.x86_64 libstdc++-7.2.1-2.fc27.x86_64 ncurses-libs-6.0-13.20170722.fc27.x86_64 nss-mdns-0.10-20.fc27.x86_64 nss-softokn-freebl-3.34.0-1.0.fc27.x86_64 openssl-libs-1.1.0g-1.fc27.x86_64 sssd-client-1.16.0-5.fc27.x86_64 systemd-libs-234-9.fc27.x86_64 zlib-1.2.11-4.fc27.x86_64                                                                                                                                                           
(gdb) bt                                                                                                                                                                          
#0  0x000000000207cdd0 in ?? ()
#1  0x00000000004019ca in write_geom() ()
#2  0x0000000000401a73 in main ()

On (L)Ubuntu box (in VM) with self-compiled ROOT I get:

Populating 'geometry.root' file:            

 *** Break *** segmentation violation       



===========================================================                              
There was a crash.                          
This is the entire stack trace of all threads:                                           
===========================================================                              
#0  0x00007f9dca14a89a in __GI___waitpid (pid=2054, stat_loc=stat_loc                    
entry=0x7ffc0bb2b1a8, options=options       
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29                                      
#1  0x00007f9dca0b99cb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148                                                                                        
#2  0x00007f9dcb8bb767 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x5615d2c727c0) at /home/vladimir/tmp/root-6.12.04/core/unix/src/TUnixSystem.cxx:2118                  
#3  TUnixSystem::StackTrace (this=0x5615d2c727c0) at /home/vladimir/tmp/root-6.12.04/core/unix/src/TUnixSystem.cxx:2412                                                            
#4  0x00007f9dcb8bdecc in TUnixSystem::DispatchSignals (this=0x5615d2c727c0, sig=kSigSegmentationViolation) at /home/vladimir/tmp/root-6.12.04/core/unix/src/TUnixSystem.cxx:3643  
#5  <signal handler called>                 
#6  0x00005615d1de9bdd in write_geom() ()   
#7  0x00005615d1de9cb9 in main ()           
===========================================================                              


The lines below might hint at the cause of the crash.                                    
You may get help by asking at the ROOT forum http://root.cern.ch/forum.                  
Only if you are really convinced it is a bug in ROOT then please submit a                
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace                   
from above as an attachment in addition to anything else                                 
that might help us fixing this issue.       
===========================================================                              
#6  0x00005615d1de9bdd in write_geom() ()   
#7  0x00005615d1de9cb9 in main ()           
=========================================================== 

under gdb:

GNU gdb (Ubuntu 8.0.1-0ubuntu1) 8.0.1                                                                                                                                             
Copyright (C) 2017 Free Software Foundation, Inc.                                                                                                                                 
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>                                                                                                     
This is free software: you are free to change and redistribute it.                                                                                                                
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"                                                                                                        
and "show warranty" for details.                                                                                                                                                  
This GDB was configured as "x86_64-linux-gnu".                                                                                                                                    
Type "show configuration" for configuration details.                                                                                                                              
For bug reporting instructions, please see:                                                                                                                                       
<http://www.gnu.org/software/gdb/bugs/>.                                                                                                                                          
Find the GDB manual and other documentation resources online at:                                                                                                                  
<http://www.gnu.org/software/gdb/documentation/>.                                                                                                                                 
For help, type "help".                                                                                                                                                            
Type "apropos word" to search for commands related to "word"...                                                                                                                   
Reading symbols from ./test_geom...(no debugging symbols found)...done.                                                                                                           
(gdb) run                                                                                                                                                                         
Starting program: /home/vladimir/tmp/root/test_geom 
[Thread debugging using libthread_db enabled]                                                                                                                                     
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".                                                                                                        
Populating 'geometry.root' file:                                                                                                                                                  
                                                                                                                                                                                  
Program received signal SIGSEGV, Segmentation fault.                                                                                                                              
0x0000555555555bdd in write_geom() ()                                                                                                                                             
(gdb) bt                                                                                                                                                                          
#0  0x0000555555555bdd in write_geom() ()
#1  0x0000555555555cb9 in main ()

(seems that I compiled ROOT without debug symbols).

To conclude:

  1. now test library and test program are compiling fine,
  2. but running test_geom gives segfault, seems to be related with my previous problem (I see reference to vtable in debug info).

I will appreciate if you guys give some hints about what is going on here. I have some experience with C++ programming both this is beyond my knowledge about C++. It looks like using ROOT classes and libraries in standalone program is too far advanced that I thought.


WBR, Vladimir Lomov

I tried get rid of TString, Double_t, Long64_t and UInt_t in my .h, .cxx files and recompile library and test program. Still I got segfault with the same last message about vtable for TString.

Another observation:

  • when I run the test_geom under valgrind:
    LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH valgrind ./test_geom
    
    and it doesn’t segfault and do the job (write root file and read from it).
  • I compiled (on Ubuntu) ROOT with Debug, compiled both library and test_geom with -ggdb and run the program under gdb. It segfaults on delete eG in write_geom function (program test_geom). I’m not sure why this line causes problem. Without it the test_geom runs fine but I still not understand why when the program segfaults I see messages about vtable for TString.

I would say I found “workaround” but I would be glad to hear comments on my observations.


WBR, Vladimir Lomov

I’m not really sure if it helps but try to add, right in the beginning of your “main”:

TApplication a("a", 0, 0); // just to make sure that the autoloading of ROOT libraries works

Hello Wile_E_Coyote,

thank you for suggestion but I think this will be useless for my use case. I have to apologize because the topic title not precisely describes my situation. I just made example that shows strange (from my pov) behavior but in actual program I need just to write to a root file.

As for segfault I faced it seems to me that this concrete case is best described here: https://isocpp.org/wiki/faq/freestore-mgmt#delete-scope.


WBR, Vladimir Lomov

In your “write_geom” routine, you must not delete eG; after geomf.Close(); as this tree is owned by this file. This tree is automatically deleted as soon as this file is closed (I guess you could reverse the sequence, first delete eG; then geomf.Close(); if you like).

Note: you should delete pos; as you own it (after the tree that uses it is deleted, of course).

ROOT User’s Guide -> Object Ownership

Hello Wile_E_Coyote,

thanks for the link. Though I read it but I forgot about that when was analyzing the test program. Now I understand why my test program works the way it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.