[C++-sig] Problem Compiling Boost.Python Example

2012-04-03 Thread Payam Shiva
Hi,

I have trouble compiling the simplest examples with Boost.Python. I
hope you could help me find out what I'm doing wrong.
I am using Microsoft Visual C++ 2010 on 64-bit Windows 7. I use 64-bit
version of Python 2.7.2 from Enthought Python Distribution 7.2-2. I
installed Boost as described in "Simplified Build From Source" section
of Boost getting started guide, i.e. going to Boost.Build directory
and typing:
bootstarp
.\b2

Boost compiled without errors (except for a warning about MPI). Then I
created user-config.jam in my home directory containing the following
lines:
using msvc : 10.0 ;
using python : 2.7 : C:\\Python 27 ;

Then I tried compiling the tutorial example, but I got the following
messages (and no DLL):
C:\Boost\boost_1_49_0\libs\python\example\tutorial> bjam
...patience...
...patience...
...found 1592 targets...
...updating 10 targets...
msvc.link.dll 
..\..\..\..\bin.v2\libs\python\build\msvc-10.0\debug\threading-multi\boost_python-vc100-mt-gd-1_49.dll
   Creating library
..\..\..\..\bin.v2\libs\python\build\msvc-10.0\debug\threading-multi\boost_python-vc100-mt-gd-1_49.l
ib and object 
..\..\..\..\bin.v2\libs\python\build\msvc-10.0\debug\threading-multi\boost_python-vc100-mt-gd-1_49.exp
function.obj : error LNK2001: unresolved external symbol __imp__PyErr_Format
numeric.obj : error LNK2019: unresolved external symbol
__imp__PyErr_Format referenced in function "void __cdecl boost::
python::numeric::`anonymous namespace'::throw_load_failure(void)"
(?throw_load_failure@?A0xd5ad2121@numeric@python@boost
@@YAXXZ)
from_python.obj : error LNK2001: unresolved external symbol __imp__PyErr_Format
registry.obj : error LNK2001: unresolved external symbol __imp__PyErr_Format
class.obj : error LNK2001: unresolved external symbol __imp__PyErr_Format
numeric.obj : error LNK2001: unresolved external symbol __imp__PyExc_ImportError
numeric.obj : error LNK2019: unresolved external symbol
__imp__PyErr_Clear referenced in function "bool __cdecl boost::p
ython::numeric::`anonymous namespace'::load(bool)"
(?load@?A0xd5ad2121@numeric@python@boost@@YA_N_N@Z)
class.obj : error LNK2001: unresolved external symbol __imp__PyErr_Clear
function.obj : error LNK2001: unresolved external symbol __imp__PyErr_Clear
object_protocol.obj : error LNK2001: unresolved external symbol
__imp__PyErr_Clear
numeric.obj : error LNK2019: unresolved external symbol
__imp__PyCallable_Check referenced in function "bool __cdecl boo
st::python::numeric::`anonymous namespace'::load(bool)"
(?load@?A0xd5ad2121@numeric@python@boost@@YA_N_N@Z)
class.obj : error LNK2001: unresolved external symbol __imp__PyCallable_Check
object_protocol.obj : error LNK2001: unresolved external symbol
__imp__PyObject_GetAttrString
wrapper.obj : error LNK2001: unresolved external symbol
__imp__PyObject_GetAttrString
numeric.obj : error LNK2019: unresolved external symbol
__imp__PyObject_GetAttrString referenced in function "bool __cde
cl boost::python::numeric::`anonymous namespace'::load(bool)"
(?load@?A0xd5ad2121@numeric@python@boost@@YA_N_N@Z)
enum.obj : error LNK2001: unresolved external symbol
__imp__PyObject_GetAttrString
class.obj : error LNK2001: unresolved external symbol
__imp__PyObject_GetAttrString
function.obj : error LNK2001: unresolved external symbol
__imp__PyObject_GetAttrString
numeric.obj : error LNK2019: unresolved external symbol
__imp__PyImport_Import referenced in function "bool __cdecl boos
t::python::numeric::`anonymous namespace'::load(bool)"
(?load@?A0xd5ad2121@numeric@python@boost@@YA_N_N@Z)
numeric.obj : error LNK2019: unresolved external symbol
__imp__PyObject_IsInstance referenced in function "public: stati
c bool __cdecl 
boost::python::numeric::aux::array_object_manager_traits::check(struct
_object *)" (?check@array_object_m
anager_traits@aux@numeric@python@boost@@SA_NPAU_object@@@Z)
from_python.obj : error LNK2001: unresolved external symbol
__imp__PyObject_IsInstance
class.obj : error LNK2001: unresolved external symbol __imp__PyObject_IsInstance
enum.obj : error LNK2001: unresolved external symbol __imp__PyEval_CallFunction
class.obj : error LNK2001: unresolved external symbol __imp__PyEval_CallFunction
pickle_support.obj : error LNK2001: unresolved external symbol
__imp__PyEval_CallFunction
stl_iterator.obj : error LNK2001: unresolved external symbol
__imp__PyEval_CallFunction
numeric.obj : error LNK2019: unresolved external symbol
__imp__PyEval_CallFunction referenced in function "class boost::
python::api::object __cdecl boost::python::call(struc
t _object *,class boost::python::api::object const &,struct
boost::type *)" (??$call@V
object@api@python@boost@@V1234@@python@boost@@YA?AVobject@api@01@PAU_object@@ABV2301@PAU?$type@Vobject@api@python@boost@
@@1@@Z)
list.obj : error LNK2001: unresolved external symbol __imp__PyEval_CallFunction
dict.obj : error LNK2001: unresolved external symbol __imp__PyEval_CallFunction
str.obj : error LNK2001: unresolved external symbol __imp__PyEval_CallFunction
function.obj : error LNK2001: unr

[C++-sig] Boost::Python to_python converter

2012-04-03 Thread DarkAnt
I'm having a conceptual issue with the way C++ interfaces with Python.
I'm trying to convert a C++ object to a Python object, but my attempt
causes the program to crash. I suspect I'm doing a lot of things
wrong. Ultimately I'd like to be able to pass C++ objects to a python
function that modifies their values.

#include 
#include 
struct Unit
{
   int health;
   std::string name;
   std::string type;
   std::pair coord;
};

struct Unit_to_python
{
   static PyObject* convert(Unit const& unit)
   {
  return boost::python::incref(boost::python::object(unit).ptr());
   }
};

BOOST_PYTHON_MODULE(game)
{
   boost::python::class_("Unit")
  .def_readwrite("health", &Unit::health)
  .def_readwrite("name", &Unit::name)
  .def_readwrite("type", &Unit::type)
  .def_readwrite("coord", &Unit::coord)
   ;
}

int main(int argc, char** argv)
{
   Py_Initialize();
   boost::python::to_python_converter();
   Unit unit1;
   unit1.health = 100;
   unit1.name = "Tank";
   unit1.type = "Armor";
   boost::python::object foo(unit1); // crash: stack overflow
   return 0;
}
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Boost::Python to_python converter

2012-04-03 Thread Stefan Seefeld
DarkAnt,

have you tried taking out the explicit to_python converter ? I don't
think you need that, as the class_ will already implicitly provide
that.
Also, out of curiosity: I'm not sure the "coord" member conversion will
work out-of-the-box, unless you also reflect std::pair to
Python using class_<> or a converter.

Stefan

-- 

  ...ich hab' noch einen Koffer in Berlin...

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Boost::Python to_python converter

2012-04-03 Thread DarkAnt
I removed everything except int health and I still crash. If I do not
have the explicit to_python converter I receive this error message:
TypeError: No to_python (by-value) converter found for C++ type: Unit

On Tue, Apr 3, 2012 at 11:20 AM, Stefan Seefeld  wrote:
> DarkAnt,
>
> have you tried taking out the explicit to_python converter ? I don't
> think you need that, as the class_ will already implicitly provide
> that.
> Also, out of curiosity: I'm not sure the "coord" member conversion will
> work out-of-the-box, unless you also reflect std::pair to
> Python using class_<> or a converter.
>
>    Stefan
>
> --
>
>      ...ich hab' noch einen Koffer in Berlin...
>
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Boost::Python to_python converter

2012-04-03 Thread Stefan Seefeld
DarkAnt,

the problem is that you don't initialize / import the newly defined
module. The attached version works fine for me.

Stefan

-- 

  ...ich hab' noch einen Koffer in Berlin...

#include 
#include 

struct Unit
{
   int health;
   std::string name;
   std::string type;
   std::pair coord;
};

namespace bpl = boost::python;

BOOST_PYTHON_MODULE(game)
{
  bpl::class_("Unit")
.def_readwrite("health", &Unit::health)
.def_readwrite("name", &Unit::name)
.def_readwrite("type", &Unit::type)
.def_readwrite("coord", &Unit::coord)
;
}

int main(int argc, char** argv)
{
  PyImport_AppendInittab( "game", &initgame); 
  Py_Initialize();
  bpl::object module = bpl::import("game");
  Unit unit1;
  unit1.health = 100;
  unit1.name = "Tank";
  unit1.type = "Armor";
  bpl::object foo(unit1);
  std::cout << bpl::extract(bpl::str(foo)) << std::endl;
}
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Boost::Python to_python converter

2012-04-03 Thread DarkAnt
Thanks a bunch Stefan!

On Tue, Apr 3, 2012 at 12:01 PM, Stefan Seefeld  wrote:
> DarkAnt,
>
> the problem is that you don't initialize / import the newly defined
> module. The attached version works fine for me.
>
>    Stefan
>
> --
>
>      ...ich hab' noch einen Koffer in Berlin...
>
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Problem Compiling Boost.Python Example

2012-04-03 Thread Adam Preble
On Tue, Apr 3, 2012 at 4:12 AM, Payam Shiva  wrote:

> Hi,
>
> I have trouble compiling the simplest examples with Boost.Python. I
> hope you could help me find out what I'm doing wrong.
> I am using Microsoft Visual C++ 2010 on 64-bit Windows 7. I use 64-bit
> version of Python 2.7.2 from Enthought Python Distribution 7.2-2. I
> installed Boost as described in "Simplified Build From Source" section
> of Boost getting started guide, i.e. going to Boost.Build directory
> and typing:
> bootstarp
> .\b2
>
> Boost compiled without errors (except for a warning about MPI). Then I
> created user-config.jam in my home directory containing the following
> lines:
> using msvc : 10.0 ;
> using python : 2.7 : C:\\Python 27 ;
>
> Then I tried compiling the tutorial example, but I got the following
> messages (and no DLL):
>

Building Boost.Python can be a real adventure.  From where I'm sitting
right now, I wouldn't be able to tell you what is wrong because I'm no
expert myself.  I had recently done a debug build, and wrote down my steps,
at home.  However, I'm betting you don't really need to build.  It looks to
me like you're not as concerned with building the DLL as you with just
using them.  If that is the case, then maybe consider the pre-built
libraries you could get here:

http://www.boostpro.com/download/

That *should* just work, but you could smash into some odd compatibility
stuff with however Enthought built their distribution--then you'd have to
build from source.
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Cplusplus-sig Digest, Vol 43, Issue 2

2012-04-03 Thread Payam Shiva
>It looks to me like you're not as concerned with building the DLL as you with 
>just
> using them.  If that is the case, then maybe consider the pre-built
> libraries you could get here:
>
> http://www.boostpro.com/download/

The problem is that my home computer, which I use for development,
isn't connected to the internet. Downloading Boost sources from school
and building them at home is the only way for me to install Boost,
because BoostPro doesn't offer an offline installer. (Well, it does.
But only for enterprise customers. That's not an option for me either)
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig