错误:distutils 扩展模块中'.hpp'未知文件类型



我正在尝试使用SWIG为某些C++代码生成Python绑定。

它创建了一些blah_wrap.cxxblah.py文件。

然后我创建了这个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'],
       )

但后来我得到了

$ 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是一个非常标准的C++扩展,对吧?为什么不.cpp?我不知道,原始代码的作者将实现放在他的头文件中。

您可以使用参数"include_dirs"。 请参阅此处的扩展文档:http://docs.python.org/2/extending/building.htmlhttp://docs.python.org/2/distutils/apiref.html#distutils.core.Extension

你确定头文件应该放在 sources 参数中,而不是另一个类似的头文件中吗?

基本上,.h.hpp做相同的工作,尝试将扩展名更改为.h,您的python脚本可能不知道.hpp文件(这并不丢人(...

最新更新