title: How to build a cython wrapper for c++ function with stl list parameter
body: <p>Consider the following simple c++ code.
  (printlist.h)</p>
  
  <pre><code>#ifndef TESTLIB_H
  #define TESTLIB_H
  
  #include &lt;iostream&gt;
  #include &lt;list&gt;
  
  void printlist(std::list&lt;int&gt; &amp;);
  
  #endif
  </code></pre>
  
  <p>(printlist.c)</p>
  
  <pre><code>#include "printlist.h"
  
  using namespace std;
  
  void printlist(list&lt;int&gt; &amp;l)
    {
    for(list&lt;int&gt;::const_iterator i = l.begin(); i != l.end(); i++)
    cout &lt;&lt; *i &lt;&lt; ' ';
    cout &lt;&lt; endl;
    }
  </code></pre>
  
  <p>My question is how to use this code with cython, the difficulty being the fact that printlist
  takes a stl::list.  Is there a way to declare this using "extern"?  If not, what is the simplest way to use this function.</p>
  
  <h1>This is my attempt:</h1>
  
  <p>(test.pyx)</p>
  
  <pre><code> from libcpp.list cimport list
  
   cdef extern from "printlist.h":
           void printlist(std::list&lt;int&gt; &amp;)
  
   cdef list[int] l = range(10)
   printlist(l)
  </code></pre>
  
  <p>(setup.py)</p>
  
  <pre><code> from distutils.core import setup
   from distutils.extension import Extension
   from Cython.Distutils import build_ext
  
   ext_modules = [Extension("test", ["test.pyx", "printlist.C"], language='c++',)]
  
   setup(cmdclass = {'build_ext': build_ext}, ext_modules = ext_modules)
  </code></pre>
  
  <p>The error message I get is the following:</p>
  
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
  ...
  from libcpp.list cimport list
  
  cdef extern from "printlist.h":
          void printlist(std::list&lt;int&gt; &amp;)
                            ^
  ------------------------------------------------------------
  
  test.pyx:4:27: Expected an identifier or literal
  </code></pre>