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

3

15

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.

  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?
Roberto answered 8/7, 2010 at 19:26 Comment(1)
possible duplicate of Determine if an executable (or library) is 32 -or 64-bits (on OSX)Unlawful
I
17

The file tool can be used to identify executables.

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
Infallibilism answered 8/7, 2010 at 19:35 Comment(1)
While this works for executables, this does not work for libraries. Doug's answer below is correct. (https://mcmap.net/q/47733/-how-to-check-if-a-library-is-32bit-64bit-built-on-mac-os-x)Cornwallis
M
8
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.

Mealymouthed answered 4/3, 2015 at 13:56 Comment(2)
"Don't use file." why?Bos
@Bos file doesn't work on all library types. It guesses formats, so you'll see this: 'libn.a: current ar archive random library' for a static library, where you'll see this from lipo: 'Non-fat file: libn.a is architecture: x86_64'. For some file types it works, but why use a tool that guesses at filetype using some 'magic tests' (see man file), instead of lipo, the tool that explicitly exists for this purpose?Mealymouthed
S
7

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

$ 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):

$ /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.maxsize for sys.maxint:

$ python3 -c "import sys;print('%x'%sys.maxsize)"
7fffffff
Subcelestial answered 8/7, 2010 at 20:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.