Search code examples
c++pythoncython

How do you tell pyximport to use the cython --cplus option?


pyximport is super handy but I can't figure out how to get it to engage the C++ language options for Cython. From the command line you'd run cython --cplus foo.pyx. How do you achieve the equivalent with pyximport? Thanks!


Solution

  • One way to make Cython create C++ files is to use a pyxbld file. For example, create foo.pyxbld containing the following:

    def make_ext(modname, pyxfilename):
        from distutils.extension import Extension
        return Extension(name=modname,
                         sources=[pyxfilename],
                         language='c++')