[C++-sig] using the same module in different files

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Tue Apr 11 02:13:53 CEST 2006


--- Abhi <abhi at qualcomm.com> wrote:

> I have 2 files
> - A.h which I want to wrap in a file boost_A.cpp
> - and B.h which I want to wrap in a file boost_B.cpp
> 
> >>> File A.h
> 
> class A
> {
>   public:
>     void fooA();
> };
> 
> >>> File B.h
> 
> class B
> {
>   public:
>     void fooB();
> };
> 
> 
> File boost_A.cpp wraps class A, while file boost_B.cpp wraps class B.
> 
> I want both these files to expose methods in the same module, ie, I want to 
> "semantically" use BOOST_PYTHON_MODULE(common) for both these files, so 
> that all the methods exposed from boost_A.cpp and boost_B.cpp get imported 
> by doing
> 
> >> import common
> >> a = common.A()
> >> b = common.B()
> 
> 
> Is this possible?

IIUC, yes. Create a file boost_common.cpp, e.g.:

void wrap_A();
void wrap_B();

BOOST_PYTHON_MODULE(common)
{
  wrap_A();
  wrap_B();
}


boost_A.cpp would look like this:

void
wrap_A()
{
  class_<A>("A")
  // ...
  ;
}

And boost_B.cpp the same with A replaced by B. Compile the three files
(boost_common.cpp, boost_A.cpp, boost_B.cpp) separately, but link like this:

g++ -shared -o common.so boost_common.o boost_A.o boost_B.o -lboost_python

HTH,
        Ralf


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Cplusplus-sig mailing list