I am trying to run i386 executable on Mac Silcon M1 Rosetta terminal -- but its says 'Bad CPU type in executable' - cpu

The executable is sm (for SuperMongo plotting routine)
=======
file sm
sm: Mach-O executable i386
so if its a valid i386 executable (which is working smoothly on older Macs)
sm
zsh: bad CPU type in executable: sm
Any suggestions are welcome!

Related

Datatable for ARM architecture?

import datatable as dt
Throws an ImportError:
ImportError: dlopen(miniforge3/lib/python3.9/site-packages/datatable/lib/_datatable.cpython-39-darwin.so, 0x0002): tried: 'miniforge3/lib/python3.9/site-packages/datatable/lib/_datatable.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))
Is there an ARM version in development?
This was resolved in https://github.com/h2oai/datatable/issues/3003#issuecomment-866386747
Running lipo -info `which clang++ will return
Architectures in the fat file: /usr/bin/clang++ are: x86_64 arm64e so you need to switch to arm64e only.
To switch to arm64 for compilation, run
env /usr/bin/arch -arm64 /bin/zsh --login
https://vineethbharadwaj.medium.com/m1-mac-switching-terminal-between-x86-64-and-arm64-e45f324184d9 details how to make aliases in your .zshrc for quickly switching between x86 and arm64.

Cannot execute Linux binary file on MacBook Air M1

I have a third party library file compiled for Linux, when I tried to execute using terminal I get the error:
cannot execute binary file:
File details are as follows:
ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for
GNU/Linux 3.2.0, BuildID[sha1]=820d7e089c6c3cdc19fa3e759ccae22fbc672652,
with debug_info, not stripped
I tried installing Rosetta, tried running with the command with a prefix arch -x86_64
but it resulted in the same error.
If I try to execute them on the terminal application directly, it shows the error:
zsh: exec format error:

How to build an Intel binary on an M1 Mac from the command line with the standard Apple version of clang?

I'm playing with some C code on my M1 MacBook Air and looking at the assembly produced with various optimization levels.
I'm building a single C file from the commandline with the most basic command:
cc foo.c -o foo
What switch do I use to build an Intel binary instead of ARM? Are there different flavours of Intel? 32 vs 64 bit? Maybe even older CPU instruction sets? This is surprisingly hard to Google for, but I'm new to the Apple ecosystem.
What about fat binaries? How would I build a single binary that contained both Intel and ARM code from the commandline?
(For the purposes of this question I'm only interested in what I can do on the commandline. If I need to set up XCode projects or environment variables, then I'll accept an answer that just says "You can't do it with just the commandline".)
Intel 32 bit is not executable on macOS since Catalina. Every Mac since 2006, except the original Intel Mac mini with Core Solo processor, is 64 bit capable.
Intel:
clang -o myTool-x86_64 -mmacosx-version-min=10.15 -arch x86_64 main.c
ARM64:
clang -o myTool-arm64 -mmacosx-version-min=10.15 -arch arm64 main.c
FAT binary:
lipo myTool-x86_64 myTool-arm64 -create -output myTool

Blender Build 2.6 in Mac OS X Lion

I have a problem with building Blender 2.6 in Mac OS X Lion.
What I have done is described here
http://wiki.blender.org/index.php/Dev:2.5/Doc/Building_Blender/Mac
but I discovered that I have to install Xcode 3, using these instructions.
http://blog.laurent.etiemble.com/index.php?post/2011/09/04/Xcode-3.2.6%2C-Lion-and-PPC-support.
However, I discovered some errors and now, while I am trying to do this:
A.) Scons Copy blender/config/darwin-config.py into the blender folder
and rename the file to user-config.py:
cd ~/blender-build/blender cp
build_files/scons/config/darwin-config.py user-config.py Then open
user-config.py and change the flags at the very top to match your
needs ( Do never(!) change darwin-config.py directly ) :
MACOSX_ARCHITECTURE needs to be set to the correct architecture : ppc,
i386 (Intel 32bit) or x86_64 (Intel 64bit) After a first successful
build, you can afterwards ("expert mode") tweak the other settings to
make an optimized build.
Note that 32bit architectures (ppc & i386) are built by default with
10.4SDK. If you are using OSX 10.6, you may need to install the 10.4 SDK that is an optional package in xcode install. Then launch the
build:
python scons/scons.py -j 2 Change "2" to the actual number of CPU
cores you have in your system to accelerate the build process.
If everything went fine, the resulting blender.app will reside here:
blender-build/install/darwin/blender.app
I receive the following error
ld: in
/Users/usersname/blender-build/build/darwin/lib/libbf_intern_guardedalloc.a,
archive has no table of contents for architecture x86_64 collect2: ld
returned 1 exit status
Do you have any idea what I can do to fix this problem?
Any suggestions?
Thanks in advance

Mac OSX 10.6 compiler: a puzzling experience with 32 vs 64 bit

I have trouble understanding the gcc compiler provided by OSX 10.6 snow leopard, mainly because of my lack of experience with 64 bits environments.
$ cat >foo.c
main() {}
$ gcc foo.c -o foo
$ file foo
foo: Mach-O 64-bit executable x86_64
$ lipo -detailed_info foo
input file foo is not a fat file
Non-fat file: foo is architecture: x86_64
However, my architecture is seen as an intel i386 type (I have one of the latest Intel Core2 duo MacBook)
$ arch
i386
and the compiler targets i686-apple-darwin10
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646)
Of course, if I compile 32 bits I get a 32 bit executable.
$ gcc -m32 foo.c -o foo
$ file foo
foo: Mach-O executable i386
but I don't get the big picture. The default setup for the compiler is to produce x86_64 executables, even if I have arch saying I have a 32 bit machine (why? Core2 is 64); even if (I guess) I am running a 32 bit kernel; even if I have a compiler targeting the i686-apple-darwin platform. Why? How can they run ? Should I compile 64 or 32 ?
This question is due to my attempt to compile gcc 4.2.3 on the mac, but I am having a bunch of issues with gmp, mpfr and libiberty getting (in some cases) compiled for x86_64. Should I compile everything x86_64 ? If so, what's the target (not i686-apple-darwin10 I guess)?
Thanks for the help
The default compiler on Snow Leopard is gcc4.2, and its default architecture is x86_64. The typical way to build Mac software is to build multiple architectures in separate passes, then use lipo to combine the results. (lipo only compiles single-arch files into a multiple-arch file, or strips archs out of a multi-arch file. It has no utility on single-arch files, as you discovered.)
The bitness of the compiler has nothing to do with anything. You can build 32-bit binaries with a 64-bit compiler, and vice versa. (What you think is the "target" of the compiler is actually its executable, which is different.)
The bitness of the kernel has nothing to do with anything. You can build and run 64-bit binaries when booted on a 32-bit kernel, and vice versa.
What matters is when you link, whether you have the appropriate architectures for linking. You can't link 32-bit builds against 64-bit binaries or vice versa. So the important thing is to see what the architectures of your link libraries are, make sure they're coherent, then build your binary of the same architecture so you can link against the libraries you have.
i686-apple-darwin10.0.0 contains an x86_64 folder which is not understood by most versions of autotools. In other words, I'd say that the gcc compiler is unfortunately nothing short of a joke on Snow Leopard. Why you would bundle 32-bit and 64-bit libraries into i686-apple-darwin10.0.0 is beyond me.
$ ls /usr/lib/gcc
i686-apple-darwin10 powerpc-apple-darwin10
You need to change all your autotools configure files to handle looking in *86-darwin directories and then looking for 64-bit libraries I'd imagine.
As with your system, my mac mini says its i386 even though its obviously using a 64-bit platform, again another mistake since its distributed with 64-bit hardware.
$arch
i386
Apple toolchains support multiple architectures. If you want to create a fat binary that contains x86 and x86_64 code, then you have to pass the parameters -arch i386 -arch x86_64 to gcc. The compiler will compile your code twice for both platforms in one go.
Adding -arch i386 -arch x86_64 to CFLAGS may allow you to compile gmp, mpfr, and whatnot for multiple archs in one go. Building libusb that way worked for me.
This answer is wrong, but see comments below
The real question is... how did you get a 32-bit version of OSX? I wasn't aware that Snow Leopard had a 32-bit version, as all of Apple's Intel chips are Core 2 or Xeon, which support the x86_64 architecture.
Oh, and Snow Leopard only works on Intel chips.
Edit: Apparently Snow Leopard starts in 32-bit mode.

Resources