简体   繁体   English

MINIX上的Python C扩展

[英]Python C extensions on MINIX

I was trying to build this package I wrote (which I know to be working), first in the usual way through distutils : 我正在尝试构建我编写的这个包 (我知道它正在工作),首先以通常的方式通过distutils

# python2.7 setup.py build
running build
running build_py
running build_ext
building 'uptime._posix' extension
gcc -fno-strict-aliasing -Wno-error -march=i586 -DHAVE_DB_185_H -I/usr/pkg/include -I/usr/include -DNDEBUG -Wno-error -march=i586 -DHAVE_DB_185_H -I/usr/pkg/include -I/usr/include -I/usr/pkg/include/python2.7 -c src/_posix.c -o build/temp.minix-3-i686-2.7/src/_posix.o
ld -L/usr/tmp/work/lang/python27/work/Python-2.7.2 -lcompat_minix -minlib -L/usr/pkg/lib -Wl,-R/usr/pkg/lib -L/usr/lib -Wl,-R/usr/lib build/temp.minix-3-   i686-2.7/src/_posix.o -o build/lib.minix-3-i686-2.7/uptime/_posix.so
ld: unrecognized option '-Wl,-R/usr/pkg/lib'
ld: use the --help option for usage information
build failed: uptime._posix (no big deal)

Well, fine; 好吧,很好; distutils is one of those modules that often break on less popular platforms. distutils是经常在不太流行的平台上破解的模块之一。 So I tried compiling the extension part manually: 所以我尝试手动编译扩展部分:

# gcc -fno-strict-aliasing -march=i586 -DNDEBUG -I/usr/pkg/include/python2.7 -fPIC -shared -o _posix.so src/_posix.c

This worked—that is, it produced _posix.so without complaining—but, trying to import the resulting module in Python didn't: 这工作 - 也就是说,它产生了_posix.so而没有抱怨 - 但是,尝试在Python中导入生成的模块没有:

>>> import _posix
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: Service unavailable

Google suggests this is related to the ability of the OS to load shared libraries (which Python extensions are). Google建议这与操作系统加载共享库(Python扩展程序)的能力有关。 I went looking, and it turns out MINIX didn't support shared libraries at all until last year , but now it should. 我去看了,直到去年 MINIX根本不支持共享库,但现在它应该。 In fact, /usr/pkg/include/python2.7/pyconfig.h defines both HAVE_DLOPEN and HAVE_DYNAMIC_LOADING , so it clearly does. 事实上,/ /usr/pkg/include/python2.7/pyconfig.h HAVE_DLOPEN / HAVE_DYNAMIC_LOADING /usr/pkg/include/python2.7/pyconfig.h定义了HAVE_DLOPENHAVE_DYNAMIC_LOADING ,所以很明显。

What's going on? 这是怎么回事?

MINIX does support shared libraries now, but the binary Python packages provided by pkgin are statically linked, which prevents them from being able to load shared libraries anyway. MINIX现在支持共享库,但pkgin提供的二进制Python包是静态链接的,这使得它们无论如何都无法加载共享库。 The only way around this is to compile Python yourself, ideally through pkgsrc . 解决这个问题的唯一方法是自己编译Python,最好是通过pkgsrc编译。 All pkgsrc packages are built dynamically by default. 默认情况下,所有pkgsrc包都是动态构建的。

(You'll still have to build the extensions manually, too.) (您仍然需要手动构建扩展。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM