[C++-sig] Help! Py++ Generated Binding Won't Compile

Rocketman@JSC snemeth at houston.rr.com
Thu Apr 12 06:25:51 CEST 2007


First of all--thanks for you guys putting in all the work to bring us Py++,
pygccxml, and boost.python--lots of hard work and I'm hoping to put it all
to good use and save us some tax dollars.

Background:  
==========
I'm trying to write a flight simulation tool with C++ sim code and models
with a Python front-end interface.  For testing purposes, I put together a
simple sim and used SWIG to start with.   Basically SWIG has no problem
generating the interfaces and all builds fine and works.  

After some research on Boost and Py++, I came to the conclusion the
Boost/Py++ solution would in the end be more robust and easier to
maintain--though the learning curve is very steep.  I know C++ pretty good
but am totally new to Py++/Boost/pygccxml.  I searched and searched with
nothing really of help--and hope you guys can set me straight.

So here I am trying to generate bindings for the same C++ sim code, but I've
run into snag.  Below I'll post the two header files I think are involved,
Py++ script, Py++ messages, and the compiler errors.

Executive.hpp
===========

#ifndef EXECUTIVE_HPP_INCLUDED
#define EXECUTIVE_HPP_INCLUDED

#include <vector>

class Event; // Forward class declarations
class Vehicle;

class Executive
{
  public:
  
    Executive(void);
   ~Executive(void);
    
    bool done;
    
    double dt;
    
    double getExecTime( void );
    
    void run( void );
    
    void run( double );
    
    void registerEvent( Event *);
    void registerVehicle( Vehicle *);
    
    double time;
    
  private:
  
    void checkEvents( void );
    
    std::vector< Event * > eventList;
    std::vector< Vehicle * > vehicleList;
};

#endif // EXECUTIVE_HPP_INCLUDED

Event.hpp
========

#ifndef EVENT_HPP_INCLUDED
#define EVENT_HPP_INCLUDED

#include <Python.h>

#include <string>

typedef enum { TGO_NONE, TRIP, REGULA_FALSI } tgo_t;

typedef enum { SLOPE_NONE, DECREASING, ANY, INCREASING } slope_t;

typedef enum { EVENT_NONE, FIXED, FLOATING, FREE }event_t;

class Executive;  // Forward class declaration 

class Event
{
  public:
    Event(void);
    Event( Executive * );
    Event( Executive *, PyObject *, PyObject *);
    
    ~Event(void);
    
    // bool setSimExec(Executive *);
    
    PyObject * setCondition(PyObject *self, PyObject *args);
    
    PyObject * setAction(PyObject *self, PyObject *args);
    
    bool check(void);
    
    bool repeating;
    
    std::string name;
    
    tgo_t tgo_type;
    
    slope_t slope;
    
    event_t event_type;
    
    bool beenFired;
    
    bool active;
    
    PyObject *condition;
    
    PyObject *action;
    
  private:
  
    Executive *exec;

};

#endif // EVENT_HPP_INCLUDED

Py++ generate_code.py file
======================
#! /usr/local/bin/python
# Copyright 2004 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

import os
import sys
sys.path.append( '../../../..' )
# Not sure about this next line
#from environment import gccxml
from pyplusplus import module_builder

mb = module_builder.module_builder_t(
        files=['Integrator.hpp','Ball.hpp', 'Executive.hpp','Event.hpp'] 
        , include_paths=['/usr/include/python2.4',
'/work/scott/python/testPy++']
	, gccxml_path='/usr/local/bin/gccxml' ) #path to gccxml executable

#I want to exclude all class methods with name starts with getPtr
getPtr_methods = mb.mem_funs( lambda decl: decl.name.startswith( 'getPtr' )
)
getPtr_methods.exclude()

ptr_to_double = mb.vars( type='double *')
ptr_to_double.exclude()

ptr_to_doubles = mb.vars( type='double * *')
ptr_to_doubles.exclude()

#I can print declarations to see what is going on
#mb.print_declarations()

#Added
mb.classes().always_expose_using_scope = True

#Now it is the time to give a name to our module
mb.build_code_creator( module_name='Pyxis' )

#It is common requirement in software world - each file should have license
mb.code_creator.license = '//Boo Hoo'

#I don't want absolute includes within code
mb.code_creator.user_defined_directories.append( os.path.abspath('.') )

#And finally we can write code to the disk
mb.write_module( os.path.join( os.path.abspath('.'), 'Pyxis_wrap.cpp' ) )

Py++ screen messages
===================
[scott at localhost testPy++]$ generate_code.py

INFO Parsing source file "Integrator.hpp" ...

INFO gccxml cmd: /usr/local/bin/gccxml  -I"." -I"/usr/include/python2.4"
-I"/work/scott/python/testPy++"   "Integrator.hpp"
-fxml="/tmp/tmpNlvtn3.xml"

INFO Parsing source file "Ball.hpp" ...

INFO gccxml cmd: /usr/local/bin/gccxml  -I"." -I"/usr/include/python2.4"
-I"/work/scott/python/testPy++"   "Ball.hpp" -fxml="/tmp/tmp9hV6e8.xml"

INFO Parsing source file "Executive.hpp" ...

INFO gccxml cmd: /usr/local/bin/gccxml  -I"." -I"/usr/include/python2.4"
-I"/work/scott/python/testPy++"   "Executive.hpp" -fxml="/tmp/tmpciXxqc.xml"

INFO Parsing source file "Event.hpp" ...

INFO gccxml cmd: /usr/local/bin/gccxml  -I"." -I"/usr/include/python2.4"
-I"/work/scott/python/testPy++"   "Event.hpp" -fxml="/tmp/tmpcFbVO_.xml"

WARNING: Event [class]
> warning W1025: Py++ will generate class wrapper - class contains T* member
> variable

WARNING: Event [class]
> warning W1025: Py++ will generate class wrapper - class contains T* member
> variable

WARNING: BallForce [class]
> warning W1040: The declaration is unexposed, but there are other
> declarations, which refer to it. This could
> cause "no to_python converter found" run time error. Declarations:  
> Ball::force [variable]

WARNING: _object [struct]
> warning W1040: The declaration is unexposed, but there are other
> declarations, which refer to it. This could
> cause "no to_python converter found" run time error. Declarations:  
> Event::Event(Executive * arg0, PyObject *> arg1, PyObject * arg2)
> [constructor]  Event::Event(Executive * arg0, PyObject * arg1, PyObject *
> arg2)
> [constructor]  PyObject * Event::setAction(PyObject * self, PyObject *
> args) [member function]  PyObject *
> Event::setAction(PyObject * self, PyObject * args) [member function] 
> PyObject * Event::setAction(PyObject *
> self, PyObject * args) [member function]  PyObject *
> Event::setCondition(PyObject * self, PyObject * args)
> [member function]  PyObject * Event::setCondition(PyObject * self,
> PyObject * args) [member function]
> PyObject * Event::setCondition(PyObject * self, PyObject * args) [member
> function]  Event::action [variable]
> Event::condition [variable]

WARNING: Executive [class declaration]
> warning W1040: The declaration is unexposed, but there are other
> declarations, which refer to it. This could
> cause "no to_python converter found" run time error. Declarations:  
> Event::Event(Executive * arg0)
> [constructor]  Event::Event(Executive * arg0, PyObject * arg1, PyObject *
> arg2) [constructor]

WARNING: BallState [class]
> warning W1040: The declaration is unexposed, but there are other
> declarations, which refer to it. This could
> cause "no to_python converter found" run time error. Declarations:  
> Ball::state [variable]

WARNING: Vehicle [class]
> warning W1040: The declaration is unexposed, but there are other
> declarations, which refer to it. This could
> cause "no to_python converter found" run time error. Declarations:   Ball
> [class]

WARNING: Vehicle [class declaration]
> warning W1040: The declaration is unexposed, but there are other
> declarations, which refer to it. This could
> cause "no to_python converter found" run time error. Declarations:   void
> Executive::registerVehicle(Vehicle *> arg0) [member function]

WARNING: Event [class declaration]
> warning W1040: The declaration is unexposed, but there are other
> declarations, which refer to it. This could
> cause "no to_python converter found" run time error. Declarations:   void
> Executive::registerEvent(Event *
> arg0) [member function]

INFO: file "Pyxis_wrap.cpp" - updated( 0.000000 seconds )

bjam compiler message
===================
[scott at localhost testPy++]$ bjam
...found 1632 targets...
...updating 2 targets...
gcc-C++-action
bin/testPy++/Pyxis.so/gcc/debug/shared-linkable-true/Pyxis_wrap.o
/apps/oss/boost_1_33_1/boost/python/object/pointer_holder.hpp: In
instantiation of ‘boost::python::objects::pointer_holder<_object*,
_object>’:
/apps/oss/boost_1_33_1/boost/type_traits/alignment_of.hpp:52:   instantiated
from ‘const size_t
boost::detail::alignment_of_impl<boost::python::objects::pointer_holder<_object*,
_object> >::value’
/apps/oss/boost_1_33_1/boost/type_traits/alignment_of.hpp:61:   instantiated
from ‘boost::alignment_of<boost::python::objects::pointer_holder<_object*,
_object> >’
/apps/oss/boost_1_33_1/boost/python/object/instance.hpp:30:   instantiated
from
‘boost::python::objects::instance<boost::python::objects::pointer_holder<_object*,
_object> >’
/apps/oss/boost_1_33_1/boost/python/object/instance.hpp:44:   instantiated
from ‘const size_t
boost::python::objects::additional_instance_size<boost::python::objects::pointer_holder<_object*,
_object> >::value’
/apps/oss/boost_1_33_1/boost/python/object/make_instance.hpp:32:  
instantiated from ‘static PyObject*
boost::python::objects::make_instance_impl<T, Holder,
Derived>::execute(Arg&) [with Arg = _object*, T = _object, Holder =
boost::python::objects::pointer_holder<_object*, _object>, Derived =
boost::python::objects::make_ptr_instance<_object,
boost::python::objects::pointer_holder<_object*, _object> >]’
/apps/oss/boost_1_33_1/boost/python/to_python_indirect.hpp:96:  
instantiated from ‘static PyObject*
boost::python::detail::make_reference_holder::execute(T*) [with T =
_object]’
/apps/oss/boost_1_33_1/boost/python/to_python_indirect.hpp:60:  
instantiated from ‘PyObject* boost::python::to_python_indirect<T,
MakeHolder>::execute(const U&, mpl_::false_) const [with U = _object, T =
PyObject*, MakeHolder = boost::python::detail::make_reference_holder]’
/apps/oss/boost_1_33_1/boost/python/to_python_indirect.hpp:48:  
instantiated from ‘PyObject* boost::python::to_python_indirect<T,
MakeHolder>::execute(U*, mpl_::true_) const [with U = PyObject, T =
PyObject*, MakeHolder = boost::python::detail::make_reference_holder]’
/apps/oss/boost_1_33_1/boost/python/to_python_indirect.hpp:37:  
instantiated from ‘PyObject* boost::python::to_python_indirect<T,
MakeHolder>::operator()(const U&) const [with U = PyObject*, T = PyObject*,
MakeHolder = boost::python::detail::make_reference_holder]’
/apps/oss/boost_1_33_1/boost/python/detail/invoke.hpp:75:   instantiated
from ‘PyObject*
boost::python::detail::invoke(boost::python::detail::invoke_tag_<false,
false>, const RC&, F&, AC0&) [with RC =
boost::python::to_python_indirect<PyObject*,
boost::python::detail::make_reference_holder>, F = PyObject* (*)(const
Event&), AC0 = boost::python::arg_from_python<const Event&>]’
/apps/oss/boost_1_33_1/boost/python/detail/caller.hpp:199:   instantiated
from ‘PyObject* boost::python::detail::caller_arity<1u>::impl<F, Policies,
Sig>::operator()(PyObject*, PyObject*) [with F = PyObject* (*)(const
Event&), Policies =
boost::python::return_value_policy<boost::python::reference_existing_object,
boost::python::default_call_policies>, Sig = boost::mpl::vector2<PyObject*,
const Event&>]’
/apps/oss/boost_1_33_1/boost/python/object/py_function.hpp:38:  
instantiated from ‘PyObject*
boost::python::objects::caller_py_function_impl<Caller>::operator()(PyObject*,
PyObject*) [with Caller = boost::python::detail::caller<PyObject* (*)(const
Event&),
boost::python::return_value_policy<boost::python::reference_existing_object,
boost::python::default_call_policies>, boost::mpl::vector2<PyObject*, const
Event&> >]’
Pyxis_wrap.cpp:333:   instantiated from here
/apps/oss/boost_1_33_1/boost/python/object/pointer_holder.hpp:176: error:
‘boost::python::objects::pointer_holder<Pointer,
Value>::pointer_holder(PyObject*) [with Pointer = _object*, Value =
_object]’ cannot be overloaded
/apps/oss/boost_1_33_1/boost/python/object/pointer_holder.hpp:111: error:
with ‘boost::python::objects::pointer_holder<Pointer,
Value>::pointer_holder(Pointer) [with Pointer = _object*, Value = _object]’

    set -e
    "g++"  -c -Wall -ftemplate-depth-255  -DBOOST_PYTHON_DYNAMIC_LIB -g -O0
-fno-inline -fPIC  -I"bin/testPy++"  -I "/usr/include/python2.4" -I
"/apps/oss/boost_1_33_1" -o
"bin/testPy++/Pyxis.so/gcc/debug/shared-linkable-true/Pyxis_wrap.o"
"Pyxis_wrap.cpp"
    "/usr/bin/objcopy" --set-section-flags .debug_str=contents,debug
"bin/testPy++/Pyxis.so/gcc/debug/shared-linkable-true/Pyxis_wrap.o"

...failed gcc-C++-action
bin/testPy++/Pyxis.so/gcc/debug/shared-linkable-true/Pyxis_wrap.o...
...skipped <@testPy++/Pyxis.so/gcc/debug/shared-linkable-true>Pyxis.so for
lack of <@testPy++/Pyxis.so/gcc/debug/shared-linkable-true>Pyxis_wrap.o...
...failed updating 1 target...
...skipped 1 target...

I don't have any clue where the problem is from these messages.  Note the
compiler mentions the 2nd to the last } of the generated wrapper
Pyxis_wrap.cpp file and all the rest of the compiler messages don't appear
to be in my code.  If I remove the Event and Executive class--all builds up
fine.

Thanks in advance for any help.

Scott

p.s.  RH FC5, gcc  version 4.1.0 20060304 (Red Hat 4.1.0-3), python 2.4,
boost_1_33_1, and Py++ 0.8.3
-- 
View this message in context: http://www.nabble.com/Help%21--Py%2B%2B-Generated-Binding-Won%27t-Compile-tf3563358.html#a9952809
Sent from the Python - c++-sig mailing list archive at Nabble.com.




More information about the Cplusplus-sig mailing list