Run macOS Terminal command with Rosetta
On macOS, Terminal commands can be specified to run with Rosetta using the arch
command.
This is useful for running or testing x86_64 software on Apple Silicon Macs.
See “man arch” for more details.
arch -x86_64 <command>
For example to run cmake
with Rosetta:
arch -x86_64 cmake -B build
The CMake variable CMAKE_SYSTEM_PROCESSOR or simply
arch -x86_64 uname -m
can be used to check the architecture of the current process.
Universal or x86_64 binaries required
When using
arch -x86_64 <command>
to run a program, the program must be a universal binary or an x86_64 binary. If not, the error message will be similar to:
arch: posix_spawnp: <command>: Bad CPU type in executable
For programs like CMake that are designed for cross-compiling, command CMake to build for x86_64 by setting the
CMAKE_OSX_ARCHITECTURES
variable to x86_64
:
cmake -B build -DCMAKE_OSX_ARCHITECTURES=x86_64
cmake --build build