On 11/17/10 5:35 PM, Imran Haque wrote:
> Hi,
>
> I have a large set of C++ molecule-manipulation libraries that
> internally use OpenBabel to handle molecule input and structure, and I'm
> trying to wrap them into a Python library using standard Python C API
> techniques. These routines work fine when called from a C program, but
> when called from the .so used for the Python library,
> OBConversion::FindFormat segfaults. I don't know how to follow the code
> path in the source code, as it appears to be generated by macros and
> eventually calls down into an independent set of .so's for each file
> format. Does anyone know how to get the molecule loader routines to work
> from dynamic libraries?

We do something similar: we link OpenBabel (C++) into the Postgres database 
(written in C).  We discovered that it is *critical* that you use the C++ 
linker, NOT the C linker, to link the final shared library.

There's a lot of linker magic that goes on behind the curtains regarding 
different versions of system libraries.  C++ has a lot of constructors and 
initialization that is triggered by the loader/linker, but if you link the 
shared object with the ordinary C linker, that stuff doesn't get initialized.  
It causes all sorts of weird and unexplainable segfaults.  Simply replacing gcc 
with g++ to create the .so solved our problem.

Craig

>
> I've put up a minimal test case at
> http://cs.stanford.edu/people/ihaque/ob_bug_repro.tar. You may have to
> adjust the paths in the Makefile to correspond to your Python and OB
> installations. Here's sample output (note that I added a tracing printf
> to OBConversion::FormatFromExt that isn't in the mainline OB 2.3.0 source):
>
> $ python numatoms.py test.sdf
> Molecule hasFilename test.sdf
> FormatFromExt calling FindFormat with arg sdf
> Segmentation fault
>
> $ ./numatoms test.sdf
> Filename test.sdf
> FormatFromExt calling FindFormat with arg sdf
> Detected format: MDL MOL format
> Reads and writes V2000 and V3000 versions
> Read Options, e.g. -as
>    s  determine chirality from atom parity flags
>          This is valid only for 0D information. Atom
>          parity is always ignored on reading for MOL files
>          containing 2D or 3D information.
>    T  read title only
>    P  read title and properties only
>          When filtering an sdf file on title or properties
>          only, avoid lengthy chemical interpretation by
>          using the T or P option together with copy format.
>
> Write Options, e.g. -x3
>    3  output V3000 not V2000 (used for>999 atoms/bonds)
>    m  write no properties
>    w  recalculate wedge and hash bonds(2D structures only)
>    A  output in Alias form, e.g. Ph, if present
>
>
> Molecule has 27 atoms.
>
>
> Thanks,
>
> Imran Haque
> http://cs.stanford.edu/people/ihaque
> iha...@stanford.edu
>
>
> PS - Using Pybel is not an option here because I don't want to
> reimplement all the C++ functionality in Python - I just need to be able
> to call into it.
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2&  L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today
> http://p.sf.net/sfu/msIE9-sfdev2dev
> _______________________________________________
> OpenBabel-discuss mailing list
> OpenBabel-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to