Ruslan
Ruslan

Reputation: 19100

Linux single binary for i386 and x86_64

Suppose I have some code which compiles and works for both plain i386 and x86_64 arches.

In DOS/Windows one could bake a single MZ-PE executable, which could have one functionality in DOS and another in Windows. Or, in OSX there's possibility to combine i386 and PPC arches in single binary.

What about i386+x86_64 in Linux (without multiarch and such stuff)? Is it possible, and how can I do this?

Upvotes: 0

Views: 550

Answers (1)

Anya Shenanigans
Anya Shenanigans

Reputation: 94584

I used to use a shell script that extracted compressed copies of the application from later in the file. Supported sparc, x86 on Solaris. It's a relatively easy way of accomplishing it, but it relied on only using the relevant binaries for the relevant platform.

That said, it's much easier to have copies in a bin-i386 and bin-x86_64 directory and use $(uname -m) in a stub shell script to direct to the relevant binary e.g.

#!/bin/bash -p

exec ${0%/*}/bin-$(uname -m)/${0##*/} "$@"

If you're trying to ship 32bit binaries for a non multi-arch 64bit system, and because most applications will be compiled with dynamic linking then libaries are an additional problem. If you are not going to do multiarch, then you *have * to ship all the relevant libraries (including the run-time linker ld.so), and use an LD_LIBRARY_PATH to pick the appropriate libraries.

Upvotes: 1

Related Questions