Boost logo

Boost :

From: Neal D. Becker (ndbecker2_at_[hidden])
Date: 2004-10-19 12:30:59


The complete test I did is this:

,----[ /disk1/nbecker/stuff/A.hpp ]
| // {{{ struct A
|
| struct A {
| int i;
| A() { i = 1; }
| static const A instance;
| };
|
| // }}}
|
| extern const A A::instance = A();
`----

,----[ /disk1/nbecker/stuff/A.cc ]
| #include <boost/python/module.hpp>
| #include <boost/python/def.hpp>
| #include <boost/python/class.hpp>
| #include <boost/python/init.hpp>
| #include <boost/python/reference_existing_object.hpp>
| #include "A.hpp"
|
| namespace python = boost::python;
|
| int get() { return int(&A::instance); }
|
| BOOST_PYTHON_MODULE(A)
| {
| python::def ("get", &get);
| }
`----
,----[ /disk1/nbecker/stuff/B.cc ]
| #include <boost/python/module.hpp>
| #include <boost/python/def.hpp>
| #include <boost/python/class.hpp>
| #include <boost/python/init.hpp>
| #include <boost/python/reference_existing_object.hpp>
| #include "A.hpp"
|
| namespace python = boost::python;
|
| int get() { return int(&A::instance); }
|
| BOOST_PYTHON_MODULE(B)
| {
| python::def ("get", &get);
| }
`----

I believe A.hpp captures the condition that Robert Ramey is concerned about
(correct me if I'm wrong).

I build A.so and B.so. Then use python to import A and B. The test is to
verify that A.get() == B.get(), which shows that A::instance has the same
address in both cases. This shows that both A.so and B.so are sharing the
same object, which I believe satisfies the requirements. Note this is only
true if you manually set python to use RTLD_GLOBAL when importing.

I would argue that the ambiguities of behaviour of dlls on various OSes (and
even different versions of the same OS) are issues outside of boost. Those
who use dlls on various platforms should already know the issues involved.
I understand the urge for caution, but I don't agree with the conclusion.
Can we at least allow the building of shared libs with a small edit to some
config file, so those of us using a platform that would work, at least for
some usages, can do so with minimal effort? I, for one, am not familiar
with boost-jam, and I don't know what files to tweak. (Right now, I am
building with scons with shared libs being built into my own local dir.)

I test on linux/x86 and linux/x86_64. On linux/x86 you can AFAIK link a
shared lib against a static lib, so there is no issue - but on linux/x86_64
you can only link shared libs with other shared libs (as is true also on
hpux IIRC).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk