On Nov 11, 2009, at 3:05 PM, J. Jankins wrote:
> <spacer.gif>
>
>
> Hello,
>
> I am trying to use C++ STL, specifically container <vector> and
> <set>. But I just find a little discription in <Cython Manual>.
The current version of Cython barely supports C++, and as there was a
GSoC project to improve this (which will get merged in the next
release) it hasn't been a priority to document the hackish way of
doing things. (Unfortunately, we still will be short of full STL
support, but we'll be a lot closer.)
> And I couldn't even to get the example to work.
>
> Here is what I do:
> 1. <stl.h>:
> #include <vector>
>
> 2. <pstl.pyx>:
> cdef extern from "stl.h":
> ctypedef struct intvec "std::vector<int>":
> void (* push_back) (int elem)
> intvec intvec_factory "std::vector<int>" (int len)
>
> def main():
> cdef intvec v = intvec_factory(2)
> v.push_back(3)
> print 'Hello'
>
> 3.<setup.py>:
> from distutils.core import setup
> from distutils.extension import Extension
> from Cython.Distutils import build_ext
>
> setup(
> name = 'Demos',
> ext_modules=[
> Extension("test",
> sources=["pstl.pyx"],
> include_dirs=["."],
> language="c++"),
> ],
> cmdclass = {'build_ext': build_ext},
> )
>
> 4. python setup.py build_ext --inplace
>
> When I import "pstl", there is an ImportError.
You may need to add
libraries=["stdc++"]
to be able to import.
> I am totally frustrated. And I commit that: I didn't finish reading
> Cython Manual. It's not that easy to understand and it has too few
> examples.
I agree, there's lots of room for improvement here. We welcome
contributions!
- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev