Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run an OS X universal binary in 32-bit mode

I have a third-party library (the interface to Xerox's Finite State tools) which come as universal binaries with two variants internally: a PPC and an i386 variant. I also have a Python interface to the library (which uses ctypes).

But when I try to run the example code provided with the Python interface I get an error complaining about the library being the wrong architecture:

ImportError: dlopen(/Users/arne/sw/lib/libxcfsm.dylib, 10): no suitable image found. Did find:
/Users/arne/sw/lib/libxcfsm.dylib: mach-o, but wrong architecture

From what I can gather, this is because the python executables have an x86_64 variant internally in addition to the two versions in my library, and prefer to run in that mode. Is there some way for me to force the python executable to start the i386 version rather than the x86_64 one, for just some scripts?

like image 256
arnsholt Avatar asked Oct 31 '09 16:10

arnsholt


People also ask

How do I run a 32-bit game on M1 Mac?

The easiest way to play 32-bit games on a Mac is to use an app such as CrossOver or Parallels. CrossOver use Wine to translate Windows applications into Mac commands. Parallels will create a virtual Windows machine on your Mac.

Does my Mac support 32-bit applications?

MacOS 10.14 Mojave, the version of the Mac operating system before macOS Catalina, is the last version that supports 32-bit software. With Catalina, only 64-bit software will be supported.

What is a macOS binary?

MacBinary is a file format that combines the two forks of a classic Mac OS file into a single file, along with HFS's extended metadata.


2 Answers

If you are using the apple system python (on snow leopard) you can execute it with

arch -i386 python

eg:

robin-mbp:~ $ arch -i386 /usr/bin/python2.6 -c "import sys; print sys.maxint"
2147483647

to start the interpreter in 32 bit mode. There is also an environment variable you can set for the system python (VERSIONER_PYTHON_PREFER_32_BIT).

If it is your own built python there is currently a bug with arch selection, but if you rebuild with the pythonw.c from this ticket it works fine.

like image 131
robince Avatar answered Sep 27 '22 21:09

robince


If you are not using the system python, you can go ahead and add a line to your ~/.bash_profile:

export VERSIONER_PYTHON_PREFER_32_BIT=yes
like image 34
Adam Greenhall Avatar answered Sep 27 '22 21:09

Adam Greenhall