[cctbxbb] Using iotbx.pdb as C++ only dynamic (shared) library

vanv0059 at umn.edu vanv0059 at umn.edu
Thu Dec 8 10:36:48 PST 2011


Hi,

The iotbx.pdb Python module is very useful and fast.

I am trying to use the C++ library and have gotten an example program to 
run correctly when compiling in the object files in cctbx_build/iotbx/pdb: 
atom_selection.o construct_hierarchy.o hierarchy.o hierarchy_atoms.o 
hierarchy_select.o hierarchy_write.o hybrid_36_c.o hybrid_36_cpp.o input.o 
input_write.o overall_counts.o utils.o write_utils.o

However, I would like to have a shared library that wraps all of the 
objects into shared library (or dynamic on Mac OSX). I have created such a 
library on my Mac using the command:

g++ -dynamiclib -fPIC -O3 --fast-math -o libiotbx_pdb.dylib 
atom_selection.o construct_hierarchy.o hierarchy.o hierarchy_atoms.o 
hierarchy_select.o hierarchy_write.o hybrid_36_c.o hybrid_36_cpp.o input.o 
input_write.o overall_counts.o utils.o write_utils.o -install_name 
/Users/jvanvoorst/Python_VEs/Lore30/lib/libiotbx_pdb.dylib 
-Wl,-single_module

When I link my program to that library I always get a segment fault in the 
deconstructor of the last instance of iotbx::pdb::hierarchy::root::~root(). 
gdb traceback is:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000000000001a
0x00000001000030e6 in std::vector<iotbx::pdb::hierarchy::model, 
std::allocator<iotbx::pdb::hierarchy::model> >::~vector ()
(gdb) where
#0 0x00000001000030e6 in std::vector<iotbx::pdb::hierarchy::model, 
std::allocator<iotbx::pdb::hierarchy::model> >::~vector ()
#1  0x00000001000035fe in iotbx::pdb::hierarchy::root_data::~root_data ()
#2 0x0000000100003662 in 
boost::checked_delete<iotbx::pdb::hierarchy::root_data> ()
#3 0x0000000100003687 in 
boost::detail::sp_counted_impl_p<iotbx::pdb::hierarchy::root_data>::dispose 
()
#4  0x0000000100001342 in boost::detail::sp_counted_base::release ()
#5  0x0000000100001372 in boost::detail::shared_count::~shared_count ()
#6 0x000000010000149b in 
boost::shared_ptr<iotbx::pdb::hierarchy::root_data>::~shared_ptr ()
#7  0x00000001000014e9 in iotbx::pdb::hierarchy::root::~root ()
#8  0x00000001000053c9 in FooBar::~FooBar ()
#9  0x0000000100001150 in main ()

I can send you my program but I have pruned FooBar down to only two class 
variables (one for a root object and the other for the input). All the 
class does is read the input from a file and construct the hierarchy. The 
seg fault only happens on the cleanup of the last object. That is if I vary 
the number of FooBar instances, the program faults on the cleanup of the 
last root object.

I tried numerous combinations of flags to the linker (g++), but (as 
expected) the result is always the same. I am using "g++ -I{include for 
sources} -I{include for build} test.C libiotbx_pdb.dylib" to compile the 
program.

I am likely overlooking something. Also, I am not proficient in debugging 
dynamic libraries via gdb. Therefore, any tips or pointers would be much 
appreciated.

If there is an edit I can make to my Sconscript to automagically generate 
the shared library I could use that as well. The libtbx/configure.py output 
looks right (Static libraries: False). However, when running scons using -Q 
the source files are getting compiled with -fPIC (good), but the libraries 
are getting created using ar (implies static libraries) -- unless I am 
looking in the wrong directory for the shared libraries (cctbx_build/lib).

Thanks,

Jeff Van Voorst










More information about the cctbxbb mailing list