macos 如何检查库是否是在 Mac OS X 上构建的 32 位/64 位?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3207177/
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-10-21 07:03:12  来源:igfitidea点击:

How to check if a library is 32bit/64bit built on Mac OS X?

pythonmacos64-bitpython-sip

提问by prosseek

I'm having some trouble in using PyQt/SIP. I guess the SIP is compiled into 64bit, but Python has some problem with finding it.

我在使用 PyQt/SIP 时遇到了一些麻烦。我猜 SIP 是编译成 64 位的,但是 Python 找到它有一些问题。

  File "qtdemo.py", line 46, in 
    import sip
ImportError: dlopen(/Library/Python/2.6/site-packages/sip.so, 2): no suitable image found.  Did find:
        /Library/Python/2.6/site-packages/sip.so: mach-o, but wrong architecture
  • How do I know if a library (so/dylib) is 32bit or 64bit?
  • How do I know if my Python is 32bit or 64bit?
  • 我怎么知道一个库(so/dylib)是 32 位还是 64 位?
  • 我怎么知道我的 Python 是 32 位还是 64 位?

回答by Nikolai Ruhe

The filetool can be used to identify executables.

file工具可用于识别可执行文件。

Example:

例子:

> file /Applications/TextEdit.app/Contents/MacOS/TextEdit 
/Applications/TextEdit.app/Contents/MacOS/TextEdit: Mach-O universal binary with 2 architectures
/Applications/TextEdit.app/Contents/MacOS/TextEdit (for architecture x86_64):   Mach-O 64-bit executable x86_64
/Applications/TextEdit.app/Contents/MacOS/TextEdit (for architecture i386): Mach-O executable i386

回答by Ned Deily

To find the available architectures in the Python instance you are using:

要在您使用的 Python 实例中查找可用架构:

$ file "$( "$(which python)" -c "import sys;print(sys.executable)" )"
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386):    Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc

To find whether the Python is currently running 32-bit or 64-bit (10.6 examples):

要查找 Python 当前运行的是 32 位还是 64 位(10.6 示例):

$ /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffffffffffff
$ arch -x86_64 /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffffffffffff
$ arch -i386 /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffff
$ arch -ppc /usr/bin/python2.6 -c "import sys;print('%x'%sys.maxint)"
7fffffff

For python3, substitute sys.maxsizefor sys.maxint:

对于python3,替换sys.maxsizesys.maxint

$ python3 -c "import sys;print('%x'%sys.maxsize)"
7fffffff

回答by Doug

lipo -info target/libexample-df07142d9bfd950a.a
input file target/libexample-df07142d9bfd950a.a is not a fat file
Non-fat file: target/libexample-df07142d9bfd950a.a is architecture: x86_64

or

或者

lipo -info `which python`
Non-fat file: /usr/local/bin/python is architecture: x86_64

Don't use file.

不要使用file.