【发布时间】:2012-05-25 12:03:47
【问题描述】:
使用 SIP 成功编译 Python/C 绑定后,我想用 Python/C++ 做同样的事情。由于某种原因,这不起作用。
这是文件:
fib.cpp
#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);
}
}
fib.h
int fib1(int n);
fib.sip
%Module fib
%Include fib.h
我运行以下命令来构建中间文件:
sip -c . fib.sip
到目前为止一切正常。
现在我想使用 distutils 构建 .pyd 文件。
setup.py
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
这会失败并出现以下错误:
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
可能是什么问题?顺便说一句,c++ 不应该用作编译器而不是 gcc 吗?
任何帮助表示赞赏!
亲切的问候
大卫
【问题讨论】:
-
c++ 是一种语言而不是编译器。 gcc 可以编译 C、C++ 等语言……见gcc.gnu.org
-
感谢回复,我知道C++是一门语言,但它也是MinGW自带的编译C++代码的可执行文件。
标签: c++ python python-sip