Re: [C++-sig] registering the same type converter in different modules with Boost.Python

2010-08-30 Thread Ger van Diepen

We had the same problem where one module registered converters for type
A and B and another module for type B and C. I do not know if Ralf's
solution caters for such situations with mixed types. 

We ended up having a private map (part of the shared library containing
our converters), so a converter gets only registered in Boost-Python if
not contained in the map.  

Cheers, 
Ger

>>> "Ralf W. Grosse-Kunstleve"  8/30/2010 8:57 AM >>>

> I have to convert std::pair to python tuple in different modules
independently.
> And these modules may be used concurrently, importing the second
module
> will report an warning like "std::pair has been already registered".

A simple and clean approach is to have another basic module that
defines the std::pair conversions,
and import that from the two modules you have already.
I never import extensions directly, but wrap each in a (possibly
trivial) Python module; this has
many advantages unrelated to your original question. Then you can
simply write:

module1.py
  import basic # e.g. with std::pair converters
  from module1_ext import *

similar for module2.py.

Ralf


___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] registering the same type converter in different modules with Boost.Python

2010-08-30 Thread Ralf W. Grosse-Kunstleve
> We had the same problem where one module registered converters for type A and 
> B 
>
> and another module for type B and C. I do not know if Ralf's solution caters 
>for 
>
> such situations with mixed types.

Yes, you just have to put B in its own module.

> We ended up having a private map (part of the shared library containing our 
> converters), so a converter gets only registered in Boost-Python if not 
> contained in the map.  

Python's import mechanism does this for free if you organize your modules in
a natural way.

Ralf
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] boost.python import problem

2010-08-30 Thread Junwei Zhang
Hi, everyone,

I just started study boost.python. and have following problem

/boostpy.cc
#include 

char const* greet()
{
  return "hello, world";
}


BOOST_PYTHON_MODULE(boostpy)
{
   using namespace boost::python;
   def("greet", greet);
}


g++ boostpy.cc  -lpython2.5 -I /usr/include/python2.5 -o boostpy.so -shared

It complies ,but when import it in python, I have following error,

<<", line 1, in 
ImportError: ./boostpy.so: undefined symbol: _ZN5boost6python6detail11init_
moduleEPKcPFvvE

any suggestion?

Thanks

--
Junwei Zhang
Office Phone:402-472-1968
[email protected]
www.junweizhang.com
Department of Electrical Engineering
University of Nebraska-Lincoln
209N Walter Scott Engineering Center
P.O. Box 880511
Lincoln, NE 68588-0511



-- 
Junwei Zhang
Office Phone:402-472-1968
[email protected]
www.junweizhang.com
Department of Electrical Engineering
University of Nebraska-Lincoln
209N Walter Scott Engineering Center
P.O. Box 880511
Lincoln, NE 68588-0511
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.python import problem

2010-08-30 Thread Charles Solar
You need to link with boost python as well.

g++ boostpy.cc  -lpython2.5 -lboost_python -I /usr/include/python2.5
-o boostpy.so -shared

should probably do the trick

On Mon, Aug 30, 2010 at 12:19 PM, Junwei Zhang
 wrote:
> Hi, everyone,
>
> I just started study boost.python. and have following problem
>
> /boostpy.cc
> #include 
>
> char const* greet()
> {
>   return "hello, world";
> }
>
>
> BOOST_PYTHON_MODULE(boostpy)
> {
>    using namespace boost::python;
>    def("greet", greet);
> }
>
>
> g++ boostpy.cc  -lpython2.5 -I /usr/include/python2.5 -o boostpy.so -shared
>
> It complies ,but when import it in python, I have following error,
>
> << Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: ./boostpy.so: undefined symbol: _ZN5boost6python6detail11init_
> moduleEPKcPFvvE
>
> any suggestion?
>
> Thanks
>
> --
> Junwei Zhang
> Office Phone:402-472-1968
> [email protected]
> www.junweizhang.com
> Department of Electrical Engineering
> University of Nebraska-Lincoln
> 209N Walter Scott Engineering Center
> P.O. Box 880511
> Lincoln, NE 68588-0511
>
>
>
> --
> Junwei Zhang
> Office Phone:402-472-1968
> [email protected]
> www.junweizhang.com
> Department of Electrical Engineering
> University of Nebraska-Lincoln
> 209N Walter Scott Engineering Center
> P.O. Box 880511
> Lincoln, NE 68588-0511
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.python import problem

2010-08-30 Thread Jim Bosch

On 08/30/2010 10:19 AM, Junwei Zhang wrote:

Hi, everyone,

I just started study boost.python. and have following problem




g++ boostpy.cc  -lpython2.5 -I /usr/include/python2.5 -o boostpy.so -shared





any suggestion?



Two compiler/linker flags: -fPIC and -lboost_python

You may have to append a suffix to get the appropriate boost_python 
shared library in some cases.


Jim Bosch
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] boost.python import problem

2010-08-30 Thread Junwei Zhang
Thanks you all

it works

On Mon, Aug 30, 2010 at 12:23 PM, Jim Bosch  wrote:
> On 08/30/2010 10:19 AM, Junwei Zhang wrote:
>>
>> Hi, everyone,
>>
>> I just started study boost.python. and have following problem
>
> 
>>
>> g++ boostpy.cc  -lpython2.5 -I /usr/include/python2.5 -o boostpy.so
>> -shared
>>
> 
>>
>> any suggestion?
>>
>
> Two compiler/linker flags: -fPIC and -lboost_python
>
> You may have to append a suffix to get the appropriate boost_python shared
> library in some cases.
>
> Jim Bosch
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



-- 
Junwei Zhang
Office Phone:402-472-1968
[email protected]
www.junweizhang.com
Department of Electrical Engineering
University of Nebraska-Lincoln
209N Walter Scott Engineering Center
P.O. Box 880511
Lincoln, NE 68588-0511
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig