Using cctbx::uctbx::unit_cell in c++ code / boosted to Python
Hi Folks,
Been working on some c++ coding using boost etc (which I have to say is great) however I found one bit of weirdness.
If I want to generate a cctbx::uctbx::unit_cell in c++ code then access this from Python I get
Traceback (most recent call last): File "tst_x2tbx.py", line 67, in <module>
tst_x2tbx(sys.argv[1])
File "tst_x2tbx.py", line 6, in tst_x2tbx
import x2tbx
File "/Users/graeme/svn/cctbx/sources/x2tbx/__init__.py", line 7, in <module>
ext = boost.python.import_ext("x2tbx_ext", optional = False)
File "/Users/graeme/svn/cctbx/sources/cctbx_project/boost_adaptbx/boost/python.py", line 36, in import_ext
+ [" "+p for p in sys.path]))
ImportError: __import__("x2tbx_ext"): dlopen(/Users/graeme/svn/cctbx/prebuild/lib/x2tbx_ext.so, 2): Symbol not found: cctbx::uctbx::unit_cell::unit_cell(scitbx::af::tiny
Interesting, adding
env.Append(LIBS=['cctbx'])
To my SConscript made this go away.
Nothing like looking at other examples…
Cheerio,
Graeme
On 25 Jan 2013, at 13:46,
Hi Folks,
Been working on some c++ coding using boost etc (which I have to say is great) however I found one bit of weirdness.
If I want to generate a cctbx::uctbx::unit_cell in c++ code then access this from Python I get
Traceback (most recent call last): File "tst_x2tbx.py", line 67, in <module> tst_x2tbx(sys.argv[1]) File "tst_x2tbx.py", line 6, in tst_x2tbx import x2tbx File "/Users/graeme/svn/cctbx/sources/x2tbx/__init__.py", line 7, in <module> ext = boost.python.import_ext("x2tbx_ext", optional = False) File "/Users/graeme/svn/cctbx/sources/cctbx_project/boost_adaptbx/boost/python.py", line 36, in import_ext + [" "+p for p in sys.path])) ImportError: __import__("x2tbx_ext"): dlopen(/Users/graeme/svn/cctbx/prebuild/lib/x2tbx_ext.so, 2): Symbol not found: cctbx::uctbx::unit_cell::unit_cell(scitbx::af::tiny
const&) Referenced from: /Users/graeme/svn/cctbx/prebuild/lib/x2tbx_ext.so Expected in: flat namespace in /Users/graeme/svn/cctbx/prebuild/lib/x2tbx_ext.so sys.path: …. unless I have
import cctbx.uctbx # explicit import
at the top of the Python code - have I done something wrong with the SConscript? I found something similar with
import scitbx.array_family.flex # explicit import
which libtbx.clean_clutter complains about as I don't reference it (hence the additional comment)
Equally I could just leave the additional clutter there but it feels like I should not need it...
Thanks,
Graeme
-- This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message. Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
_______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
-- This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message. Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
On 25 Jan 2013, at 14:46, [email protected] 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
Hi Luc,
Funny. On my OS X system solution #1 appeared to work well!
I looked at some other SConscripts on how to do this & copied.
Thanks for the description though - this hybrid programming stuff takes a little getting used to...
Cheerio,
Graeme
From: [email protected] [mailto:[email protected]] On Behalf Of Luc Bourhis
Sent: 25 January 2013 14:21
To: cctbx mailing list
Subject: Re: [cctbxbb] Using cctbx::uctbx::unit_cell in c++ code / boosted to Python
On 25 Jan 2013, at 14:46, [email protected]mailto:[email protected] 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
On 25 Jan 2013, at 15:25, [email protected] wrote:
Funny. On my OS X system solution #1 appeared to work well!
Does the following work too? import x2tbx import cctbx.uctbx Best wishes, Luc
Yep. Works just fine. Where by work I assume you mean, does typing the following into a new cctbx.python session result in no apparent errors. Very pleased actually with how well everything is working. Cheerio, Graeme From: [email protected] [mailto:[email protected]] On Behalf Of Luc Bourhis Sent: 25 January 2013 14:30 To: cctbx mailing list Subject: Re: [cctbxbb] Using cctbx::uctbx::unit_cell in c++ code / boosted to Python On 25 Jan 2013, at 15:25, [email protected]mailto:[email protected] wrote: Funny. On my OS X system solution #1 appeared to work well! Does the following work too? import x2tbx import cctbx.uctbx Best wishes, Luc -- This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message. Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
On 25 Jan 2013, at 15:32, [email protected] wrote:
Yep. Works just fine.
I'm surprised! Mmhmmm… I'll investigate that. Basically, those 2 imports should end up bringing into your Python process two copies of each symbol in libcctbx and I was under the impression that it should spell trouble.
Very pleased actually with how well everything is working.
I have fond memories of the first time I got a Boost Python module working too! Best wishes, Luc
On Fri, Jan 25, 2013 at 5:46 AM,
unless I have
import cctbx.uctbx # explicit import
at the top of the Python code - have I done something wrong with the SConscript? I found something similar with
import scitbx.array_family.flex # explicit import
which libtbx.clean_clutter complains about as I don't reference it (hence the additional comment)
Equally I could just leave the additional clutter there but it feels like I should not need it...
FYI, this will not be complained about: import cctbx.uctbx # import dependency since in practice there are multiple other situations (some involving just pure Python, no Boost) where we've found it necessarily to import something but not directly reference it again. -Nat
participants (4)
-
Graeme.Winter@diamond.ac.uk
-
Luc Bourhis
-
Nathaniel Echols
-
Phzwart