编译的Python下用用Cython来 [英] Compiling Python to C using Cython

查看:282
本文介绍了编译的Python下用用Cython来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的蟒蛇源$ C ​​$ C foo.py为C =htt​​p://cython.org/相对= nofollow的> 用Cython

I'm trying to compile python source code foo.py to C using cython.

foo.py

print "Hello World"

我跑的命令是用Cython foo.py

问题是,使用 编译foo.c的当GCC ,我得到的错误:

The problem is that when compiling foo.c using gcc, I get the error:

未定义引用主

推荐答案

从蟒蛇转换code到C时(使用用Cython)它转换为C code可以编译成一个共享对象。
为了使其可执行,您应该添加--embed来用Cython转换命令。该标志将您所需要的'主'的功能,所以你可以编译C code到可执行文件。
请注意,您需要蟒蛇的.so 运行时库才能运行exec。

when converting the code from python to c (using Cython) it converts it to c code which can be compiled into a shared object. in order to make it executable, you should add "--embed" to cython conversion command. this flag adds the 'main' function you need, so you could compile the c code into executable file. please notice you'll need the python .so runtime libraries in order to run the exec.

这篇关于编译的Python下用用Cython来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆