Hi Jeff,<div><br></div><div>Did you copy all the -DXXX that you see on the compilation line for the iotbx/pb files? In particular, the -DBOOST_DISABLE_THREADS is probably critical, but highly I recommend you copy all -DXXX. Otherwise you&#39;ll most likely violate the C++ One Definition Rule (ODR) which could explain your crash.</div>
<div><br></div><div>Did you try to link against lib/libiotbx_pdb.a instead of the .o files? (On the Mac I couldn&#39;t figure out how to link dynamically loaded Python extensions against shared libraries, but it is probably 7+ years ago that I tried the last time.)</div>
<div><br></div><div>Ralf<br><br><div class="gmail_quote">On Thu, Dec 8, 2011 at 10:36 AM,  <span dir="ltr">&lt;<a href="mailto:vanv0059@umn.edu">vanv0059@umn.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
The iotbx.pdb Python module is very useful and fast.<br>
<br>
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<br>

<br>
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:<br>
<br>
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/<u></u>Lore30/lib/libiotbx_pdb.dylib -Wl,-single_module<br>

<br>
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::~<u></u>root(). gdb traceback is:<br>
<br>
Program received signal EXC_BAD_ACCESS, Could not access memory.<br>
Reason: KERN_INVALID_ADDRESS at address: 0x000000000000001a<br>
0x00000001000030e6 in std::vector&lt;iotbx::pdb::<u></u>hierarchy::model, std::allocator&lt;iotbx::pdb::<u></u>hierarchy::model&gt; &gt;::~vector ()<br>
(gdb) where<br>
#0 0x00000001000030e6 in std::vector&lt;iotbx::pdb::<u></u>hierarchy::model, std::allocator&lt;iotbx::pdb::<u></u>hierarchy::model&gt; &gt;::~vector ()<br>
#1  0x00000001000035fe in iotbx::pdb::hierarchy::root_<u></u>data::~root_data ()<br>
#2 0x0000000100003662 in boost::checked_delete&lt;iotbx::<u></u>pdb::hierarchy::root_data&gt; ()<br>
#3 0x0000000100003687 in boost::detail::sp_counted_<u></u>impl_p&lt;iotbx::pdb::hierarchy::<u></u>root_data&gt;::dispose ()<br>
#4  0x0000000100001342 in boost::detail::sp_counted_<u></u>base::release ()<br>
#5  0x0000000100001372 in boost::detail::shared_count::~<u></u>shared_count ()<br>
#6 0x000000010000149b in boost::shared_ptr&lt;iotbx::pdb::<u></u>hierarchy::root_data&gt;::~<u></u>shared_ptr ()<br>
#7  0x00000001000014e9 in iotbx::pdb::hierarchy::root::~<u></u>root ()<br>
#8  0x00000001000053c9 in FooBar::~FooBar ()<br>
#9  0x0000000100001150 in main ()<br>
<br>
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.<br>

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

<br>
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.<br>
<br>
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).<br>

<br>
Thanks,<br>
<br>
Jeff Van Voorst<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
cctbxbb mailing list<br>
<a href="mailto:cctbxbb@phenix-online.org" target="_blank">cctbxbb@phenix-online.org</a><br>
<a href="http://phenix-online.org/mailman/listinfo/cctbxbb" target="_blank">http://phenix-online.org/<u></u>mailman/listinfo/cctbxbb</a><br>
</blockquote></div><br></div>