如何知道 libpython27.a 是 32 位还是 64 位?

How to know whether libpython27.a is 32-bit or 64-bit?

我有一个 libpython27.a 文件:如何在 Windows 7 x64 上知道它是 32 位还是 64 位?

在 terminal/command 行中启动 Python 解释器时,您可能还会看到如下行:

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32

其中 [MSC v.1500 64 位 (AMD64)] 表示 64 位 Python。

尝试使用 ctypes 获取 void 指针的大小:

import ctypes
print ctypes.sizeof(ctypes.c_voidp)

32 位为 4,64 位为 8。

尝试dumpbin /headers "libpython27.a"。 (dumpbin reference)

输出将包含

FILE HEADER VALUES 14C machine (x86)

FILE HEADER VALUES 8664 machine (x64)


请注意,如果您收到如下错误消息:

E:\temp>dumpbin /headers "libpython27.a"
LINK: extra operand `libpython27.a'
Try `LINK --help' for more information.

这意味着在搜索路径的某处有一个 GNU link 实用程序的副本。确保使用正确的 link.exe(例如 C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python.0\VC\bin 中提供的那个)。它还需要 mspdb80.dll,它在同一个文件夹或 PATH 中的某个地方,否则你会收到错误消息:

在 Linux 上,您可以使用:objdump -a libpython27.a|grep 'file format'

示例:

f@f-VirtualBox:/media/code$ objdump -a libpython27.a|grep 'file format'
dywkt.o:     file format pe-i386
dywkh.o:     file format pe-i386
dywks01051.o:     file format pe-i386
dywks01050.o:     file format pe-i386
dywks01049.o:     file format pe-i386
dywks01048.o:     file format pe-i386
[...]