[cctbxbb] Using cctbx::uctbx::unit_cell in c++ code / boosted to Python

Luc Bourhis luc_j_bourhis at mac.com
Fri Jan 25 06:21:24 PST 2013


On 25 Jan 2013, at 14:46, Graeme.Winter at Diamond.ac.uk wrote:

> Equally I could just leave the additional clutter there but it feels like I should not need it...

You have a function "generate_unit_cell" written in C++ whose body creates a new unit_cell object and that is exposed to Python with Boost Python inside a module x2tbx. When Python loads that module, the linker of your OS is asked to resolve all symbols in your x2tbx.so. It finds a constructor 
	cctbx::uctbx::unit_cell::unit_cell(scitbx::af::tiny<double, 6ul> const&)
but it does not know what code it shall run for it. That's because that code is in cctbx/uctbx/uctbx.cpp that has been compiled and linked into a library libcctbx. Thus you have 2 solutions here: (1) either you link that library with your x2tbx.so (modify the SConscript for that), or (2) just import a Boost Python wrapper that has been linked with that library. The line "import cctbx.uctbx" belongs to solution (2) because the uctbx Python module loads the Boost Python uctbx wrappers that is linked with libcctbx. As for solution (1), beware Dragons here! It will reliably work only if all libraries are dynamic. Currently, libcctbx is a static library on MacOS and you will run into troubles on that platform with that solution (1). As it has been discussed in the past on this very forum, there is no good reason that we keep using static libs on MacOS but until somebody spends time to fix that, you are stuck with solution (2).

Best wishes,

Luc



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://phenix-online.org/pipermail/cctbxbb/attachments/20130125/1c6b3509/attachment.htm>


More information about the cctbxbb mailing list