On Sun, Jan 31, 2010 at 6:23 PM, Chris Lasher <chris.las...@gmail.com> wrote:
> I asked this question on Stack Overflow, but realized that perhaps few from
> the Py++ community are there yet. I'm re-posting the question here; I hope
> you don't mind.
>
> http://stackoverflow.com/questions/2169948/using-code-generated-by-py-as-a-python-extension

I will answer here, would you mind to upload the answer to
stackoverflow? Thanks.

>
> I have a need to wrap an existing C++ library for use in Python.
> reading through this answer
> http://stackoverflow.com/questions/456884/extending-python-to-swig-or-not-to-swig/456949#456949
> on choosing an appropriate method to wrap C++ for use in Python, I decided
> to go with Py++.
>
> I walked through the tutorial for Py++
> http://www.language-binding.net/pyplusplus/documentation/tutorials/module_builder/module_builder.html
> , using the tutorial files, and I got the expected output in generated.cpp,
> but I haven't figured out what to do in order to actually use the generated
> code as an extension I can import in Python. I'm sure I have to compile the
> code, now, but with what? Am I supposed to use bjam?

After you generated the code you have to compile it and for this
purpose you can use your favorite build system. I use bjam only to
compile boost. After this, I prefer to use scons ( on Windows and on
Linux ).

The following is an example of sconstruct file, which is used to
compile one of the Py++ unittests:
( this is a generated code too :-) )

import sys
env = Environment()
if 'linux' not in sys.platform:
    env['MSVS'] = {'VERSION': ''}
    env['MSVS_VERSION'] = ''
    Tool('msvc')(env)
t = env.SharedLibrary( target=r'abstract_classes'
    , source=[ 
r'/home/roman/language-binding/sources/pyplusplus_dev/unittests/temp/abstract_classes.cpp'
]
    , LIBS=[ r"boost_python" ]
    , LIBPATH=[ r"",r"/home/roman/include/libs" ]
    , CPPPATH=[
r"/home/roman/boost_svn",r"/usr/include/python2.6",r"/home/roman/language-binding/sources/pyplusplus_dev/unittests/temp",r"/home/roman/language-binding/sources/pyplusplus_dev/unittests/data",r"/home/roman/boost_svn"
]
    , CCFLAGS=[  ]
    , SHLIBPREFIX=''
    , SHLIBSUFFIX='.so'
)

Since your code generator written in Python, you can continue where
Py++ stops and generate your favorite "make" file. You can go even
father. Py++ tests generate the code, compile, load new module and
test the functionality. All this is done in a single, stand alone
process.

HTH

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to