作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
经过长时间的搜索没有任何结果,我需要一些帮助。
我正在尝试调用 C 形式的 Cython 函数。我有以下代码:
打印.pyx
cdef public int grail(int i, int a): # public function declaration
return (i+a)
modul.c
#include <Python.h>
#include "print.h"
#include <stdio.h>
void main(void) {
int a;
Py_Initialize();
initprint();
a = grail(2,3);
printf("%i\n", a);
Py_Finalize();
}
我尝试了两种方法来编译和链接它,但链接总是失败。
首先使用命令行:
cython print.pyx
gcc -LD:\Anaconda\libs -ID:\Anaconda\include -o print.exe print.c modul.c -lpython27 -g
第二个是setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("print", ["print.pyx", "modul.c"])]
)
然后在命令行上:
python setup.py build_ext --inplace
在这两种情况下我都遇到了相同的错误:
build\temp.win32-2.7\Release\modul.o:modul.c:(.text+0x2a): undefined reference t
o `__imp__grail'
以下是有关我的系统的一些附加信息:
Python 2.7.7::Anaconda 2.0.1(32 位)
海湾合作委员会(GCC)4.7.0 20111219
Cython 版本 0.20.1
Windows 7 企业版 x64
我希望有人知道我如何解决这个问题,但已经非常感谢您的帮助。
致以诚挚的问候
最佳答案
如果我是你,我会从 CFFI 开始,而不是手动编写:
http://eli.thegreenplace.net/2013/03/09/python-ffi-with-ctypes-and-cffi
不过,我不确定它在 Windows 上的运行情况如何(对我来说,它在 Linux 上运行得很好)。它可能会起作用,因为 CFFI 项目声称这是关于 Windows 的:
关于python - 从 C Windowsx64 调用 Cython 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24990320/
我是一名优秀的程序员,十分优秀!