cythonize and support files (c/cpp)

93 views
Skip to first unread message

Didrik Pinte

unread,
Feb 14, 2012, 6:32:28 PM2/14/12
to cython-users
Hi,

I am heavily using the cythonize call in my setup.py. It helps a lot but I am stuck with one issue. Submitting to the list before looking into the code ;-)

Some of my pyx file depend on cpp support code (sometimes more than one files).

Is there a way to add a directive, just like the "# distutils: language = c++" inside of the pyx file itself that could list the dependant cpp files ?

Thanks

-- Didrik

Robert Bradshaw

unread,
Feb 15, 2012, 1:02:14 AM2/15/12
to cython...@googlegroups.com

I'm a bit unclear what you mean by "support code" but if you're just
talking about files listed in the sources attribute along with your
pyx file, you could simply write

cdef extern from "support.cpp":
pass

and it would insert an #include "support.cpp" into the generated C.

- Robert

Morgan Martinet

unread,
Feb 15, 2012, 10:11:09 AM2/15/12
to cython...@googlegroups.com

Hi,
To compile pyx files in cpp you can use the create_extension_list method before use cythonize:

from Cython.Build.Dependencies import create_extension_list

modules_list = create_extension_list("*_cpp.pyx",exclude=["*_c.pyx"])
for module in modules_list:
module.language = "c++"
ext_modules = cythonize(pyx_modules)

Didrik Pinte

unread,
Feb 15, 2012, 6:45:52 PM2/15/12
to cython...@googlegroups.com

Yes my intention was being able to replace manual extension I had to create with a list of source file like ['myextension.pyx', 'code1.cpp', 'code2.cpp']

Thanks for the hint, it works fine.

-- Didrik
Reply all
Reply to author
Forward
0 new messages