문제

I'm trying to generate Python bindings for some C++ code using SWIG.

It created some blah_wrap.cxx and blah.py files.

I then created this setup.py

from distutils.core import setup, Extension

ext = Extension('_ev3',
    sources=[
        'ev3_serial_wrap.cxx',
        'ev3_serial.hpp'
        'ev3_motor_wrap.cxx',
        'ev3_motor.hpp'
        'ev3_i2c_wrap.cxx',
        'ev3_i2c.hpp'
        'ev3_analog_wrap.cxx',
        'ev3_analog.hpp'
    ],
    language='c++',
)

setup (name = 'evpy',
       version = '0.1',
       author      = "Pepijn de Vos",
       description = """
       An EV3 API.
       """,
       ext_modules = [ext],
       packages=['evpy'],
       )

But then I get

$ python3 setup.py build
running build
running build_py
running build_ext
building '_ev3' extension
error: unknown file type '.hpp' (from 'ev3_analog.hpp')

.hpp is a pretty standard C++ extensions right? Why not .cpp? I don't know, the author of the original code put the implementation in his header files.

도움이 되었습니까?

해결책 2

Are you sure header files are supposed to go in the sources argument, and not in another like headers?

다른 팁

You can use the parameter "include_dirs". See the documentation for Extension here: http://docs.python.org/2/extending/building.html http://docs.python.org/2/distutils/apiref.html#distutils.core.Extension

Basically, .h and .hpp do the same jobs, try to change the extension to .h, your python script might not know .hpp files (which is not a shame)...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top