1

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.

Pepijn
  • 4,145
  • 5
  • 36
  • 64
  • `distutils` will use SWIG to generate the `_wrap.cxx` when you use the command `python setup.py build_ext`. I don't think it's required to include the `_wrap.cxx` files in your `sources` list, but this is probably not the source of the error – mark jay Dec 30 '16 at 22:53

3 Answers3

1

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

dkamm
  • 345
  • 4
  • 6
0

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)...

Anthon
  • 69,918
  • 32
  • 186
  • 246
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
0

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

merwok
  • 6,779
  • 1
  • 28
  • 42