After successfully compiling a Python/C binding with SIP I wanted to do the same thing with Python/C++. For some reason this doesn't work.
Here's the files:
fib.cpp
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
- #include "fib.h"
- int fib1(int n)
- {
- if (n <= 0) {
- return 0;
- } else if (n <= 2) {
- return 1;
- } else {
- return fib1(n-1) + fib1(n-2);
- }
- }
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
- int fib1(int n);
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
- %Module fib
- %Include fib.h
sip -c . fib.sip
So far everything works.
Now I want to build the .pyd file using distutils.
setup.py
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
- from distutils.core import setup, Extension
- import sipdistutils
- setup(
- name = 'fib',
- versione = '1.0',
- ext_modules=[
- Extension("fib", ["fib.sip", "fib.cpp"]),
- ],
- cmdclass = {'build_ext': sipdistutils.build_ext}
- )
python setup.py build
This fails with the following error:
build\temp.win32-2.7\Release\sipfibcmodule.cpp:29:29: error: 'fib1' was not declared in this scope
error: command 'gcc' failed with exit status 1
What could the problem be? Shouldn't c++ be used as a compiler instead of gcc, by the way?
Any help appreciated!
Kind regards
David