Contents
Do you need a compiler for each architecture?
Elizabeth Myers is correct, each architecture requires a compiled binary for the architecture in question. To build binaries for a different architecture than your system runs on you need a cross-compiler. In most cases you need to compile a cross compiler.
How is an ABI used in compiler construction?
An ABI can define a standard way of encoding the name of a function so that programs built with a different language or compiler can locate what they need. When you use extern “c” in a C++ program, you’re instructing the compiler to use a standardized way of recording names that’s understandable by other software.
Why are there different ABI’s for Linux and Windows?
Linux and Windows use different ABIs, so a Windows program won’t know how to access a library compiled for Linux. Sometimes, ABI changes are unavoidable. When this happens, any programs that use that library will not work unless they are re-compiled to use the new version of the library.
Which is the Portable Executable format for IIRC?
IIRC, Windows currently uses the Portable Executable (or, PE) format. There are links in the “external links” section of that Wikipedia page with more information about the PE format. Also, regarding your note about C++ name mangling: When locating a function in a library file, the function is typically looked up by name.
Is it possible to run binary on different platforms?
Since it is often slow or impossible to run a binary on a different OS/architecture platform, it is a common practice to build your final binary for many different platforms to maximize your program’s audience.
How to control which OS a binary is built for?
By using environment variables and build tags, you can control which OS and architecture your final binary is built for, in addition to putting together a workflow that can quickly toggle the inclusion of platform-dependent code without changing your codebase.
Is there a way to bootstrap a cross compiler?
Another option is a bootstrap compilation of a cross-compiler. Thanks to the struggle of compiling cross compilers to different architectures on different architectures crosstool-ng was created. It gives a bootstrap over the toolchain needed to build a cross compiler.