如何在 64 位 Linux 上构建 32 位 python 2.6?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3867131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:35:19  来源:igfitidea点击:

How to build 32bit python 2.6 on 64bit Linux?

pythonlinuxbuild32bit-64bit

提问by Philipp

I'm stuck for a full afternoon now trying to get python to build in 32bit mode. I run a 64bit Linux machine with openSUSE 11.3, I have the necessary -devel and -32bit packages installed to build applications in 32bit mode.

我被困了一个完整的下午,现在试图让 python 以 32 位模式构建。我运行带有 openSUSE 11.3 的 64 位 Linux 机器,我安装了必要的 -devel 和 -32bit 包以在 32 位模式下构建应用程序。

The problem with the python build seems to be not in the make run itself, but in the afterwards run of setup.py, invoked by make.

python 构建的问题似乎不在于 make 运行本身,而是在由 make 调用的 setup.py 的后续运行中。

I found the following instructions for Ubuntu Linux: h**p://indefinitestudies.org/2010/02/08/how-to-build-32-bit-python-on-ubuntu-9-10-x86_64/

我找到了 Ubuntu Linux 的以下说明:h**p://indefinestudies.org/2010/02/08/how-to-build-32-bit-python-on-ubuntu-9-10-x86_64/

When I do as described, I get the following output:

当我按照描述做时,我得到以下输出:

http://pastebin.com/eP8WJ8V4

http://pastebin.com/eP8WJ8V4

But I have the -32bit packages of libreadline, libopenssl, etc.pp. installed, but of course, they reside under /lib and /usr/lib and not /lib64 and /usr/lib64.

但是我有 libreadline、libopenssl 等 -32 位包。已安装,但当然,它们驻留在 /lib 和 /usr/lib 下,而不是 /lib64 和 /usr/lib64。

When I start the python binary that results from this build, i get:

当我启动由此构建产生的 python 二进制文件时,我得到:

./python
Python 2.6.6 (r266:84292, Oct  5 2010, 21:22:06) 
[GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "/etc/pythonstart", line 7, in <module>
    import readline
ImportError: No module named readline

So how to get setup.py to observe the LDFLAGS=-L/lib command??

那么如何获取setup.py来观察LDFLAGS=-L/lib命令呢??

Any help is greatly appreciated.

任何帮助是极大的赞赏。

Regards, Philipp

问候, 菲利普

采纳答案by James Mills

You'll need to pass the appropriate flags to gcc and ld to tell the compiler to compile and produce 32bit binaries.

您需要将适当的标志传递给 gcc 和 ld 以告诉编译器编译和生成 32 位二进制文​​件。

Use --buildand --host.

使用--build--host

./configure --help
System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

You need to use ./configure --build=x86_64-pc-linux-gnu --host=i686-pc-linux-gnuto compile for 32-bit Linux in a 64-bit Linux system.

您需要使用./configure --build=x86_64-pc-linux-gnu --host=i686-pc-linux-gnu在 64 位 Linux 系统中为 32 位 Linux 进行编译。

Note:You still need to add the other ./configureoptions.

注意:您仍然需要添加其他./configure选项。

回答by Finn Espen

Regarding why, since Kirk (and probably others) wonder, here is an example: I have a Python app with large dicts of dicts containing light-weight objects. This consumes almost twice as much RAM on 64bit as on 32bit simply due to the pointers. I need to run a few instances of 2GB (32bit) each and the extra RAM quickly adds up. For FreeBSD, a detailed recipe for 32bit-on-64bit jail is here http://www.gundersen.net/32bit-jail-on-64bit-freebsd/

关于原因,因为 Kirk(可能还有其他人)想知道,这里有一个例子:我有一个 Python 应用程序,其中包含包含轻量级对象的大型 dicts。由于指针的原因,这在 64 位上消耗的 RAM 几乎是 32 位上的两倍。我需要运行几个 2GB(32 位)的实例,并且额外的 RAM 很快就会增加。对于 FreeBSD,32bit-on-64bit jail 的详细配方在这里http://www.gundersen.net/32bit-jail-on-64bit-freebsd/