I'd like to add some more detail to what Sam said. I may make a mistake trying to simplify something very technical. I apologize in advance if I make a mistake. Please correct me.
As Sam states, binaries "MAY NOT" run on different distro's, but it isn't because of Linux itself. While I agree Linux isn't a plug and play OS like Windows, ALL distro's use the same kernel from the Linux Foundation (
https://www.linuxfoundation.org/). Yes, Arch Linux does incorporate the newest release of the kernel, whereas Ubuntu, Mint and others use a stable release behind the latest and greatest.
All else being equal, creating a binary in Ubuntu using GCC should run theoretically on all Linux machines.
What also needs to be considered is your hardware's architecture. Are you running on a i386, i686, amd64 or a x86_64 system? Or are you running on a M1, ARM or armhf hardware? 32-bit or 64-bit system? Maybe even on an older i286 running 16-bit?
When GCC creates the binary, it takes the libraries from your machine instruction set based on your hardware. So if I compile a QB64 program on my x86_64 machine running Ubuntu, you should be able to run it on any distro running on a x86_64 machine, all else (GUI and display server as an example) being the same. If you try to run it on an i386 machine, it will not work. Same goes for a M1 (Apple's ARM processor) or an ARM or ARMhf architecture. Or an i386 running 32-bit instead of 64-bit.
Even GNU says:
We are often asked about pre-compiled versions of GCC. While we cannot provide these for all platforms, below you’ll find links to binaries for various platforms where creating them by yourself is not easy due to various reasons.
Here is a link to a list of specific GCC libraries based on host platforms:
https://gcc.gnu.org/install/specific.htmlIf you want to know what processor you are running on in Linux, in a terminal type in "uname -m" and it will display something like x86_64 or i386. And yes, while the i386 instruction set is a subset of the x64 instruction set, you can't run x64 in an i386 architecture.
If you want to read about processor compatibility, an excellent article is:
http://www.aliencoders.org/content/basic-information-about-i386-i686-and-x8664-architectures/. This does not
The more libraries that GCC uses in your binary from your architecture type, the less compatible it will be with other systems.
Another factor is whether or not I incorporate GUI components from one Linux distro. Say in Ubuntu I develop a program that uses GNOME for my GUI (gdialog or now Zenity). My binary from Ubuntu will work on Debian and Linux Mint (I've tested this) that use GNOME, but binaries that use the GNOME libraries will not run on Linux distro's that uses XFCE, MATE, OpenBox, LXDE, Cinnamon, Budgie, KDE Plasma, and other GUI libraries. Yes, you can install GNOME on Arch Linux, but why? Only thing I can think of is if you need that compatibility would you do this.
Even if you are running Ubuntu 20.04, your binary may not work on Ubuntu 21.04. I say may not, because 20.04 uses X11, where 21.04 and newer will use Wayland. X11 and Wayland are what is called "display servers," and they also have different libraries that may be pulled into your binary at creation time. I believe Arch Linux has already moved to Wayland, where Ubuntu will do so officially next year with it's 22.04 LTS release, coming sometime in April.
This may be too technical for some, to simplified for others, but I hope this helps in some greater detail on why in Linux binaries may or may not run on different distro's.