[英]Cython and gcc: can't run compiled program
I have a problem with python to C code translation and further compilation. 我有一个python到C代码转换和进一步编译的问题。
First, I installed MinGW, wrote `setup.py? 首先,我安装了MinGW,写了`setup.py? script and translated python code (simplest helloworld) to C with Cython:
使用Cython将脚本和已翻译的python代码(最简单的helloworld)转换为C:
python setup.py build_ext --inplace
Then I tried to compile generated .c file: 然后我尝试编译生成的.c文件:
gcc.exe helloworld.c -mdll -IC:\\Python27\\include -IC:\\Python27\\PC -LC:\\Python27\\libs -LC:\\Python27\\PCbuild -lpython27 -lmsvcr90
No error occurred during compilation, but when I tried to launch generated a.exe file, I got the following error: 编译期间没有发生错误,但是当我尝试启动生成的a.exe文件时,出现以下错误:
a.exe is not a valid Win32 application
a.exe不是有效的Win32应用程序
I have no idea how to fix this problem. 我不知道如何解决这个问题。
I'm running 32-bit Vista. 我正在运行32位Vista。
PS Sorry for my poor English. PS抱歉我的英语不好。
请参阅Cython wiki on Embedding Cython,以便使用Cython创建独立的可执行文件
The compiled file isn't an executable, it's a library ( dll
). 编译后的文件不是可执行文件,它是一个库(
dll
)。
python modules on windows usually have a .pyd
extension, so either rename your file to helloworld.pyd
or use -o helloworld.pyd
as argument for the compiler. Windows上的python模块通常具有
.pyd
扩展名,因此要么将文件重命名为helloworld.pyd
要么使用-o helloworld.pyd
作为编译器的参数。
then you should be able to import helloworld
from python. 那么你应该能够从python
import helloworld
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.