The general way to build a binary without runtime library dependencies is to build it to be static, ie. using the -static
argument to gcc, which links in static versions of the libraries required such that they're included in the resulting executable. This doesn't bundle in any data file dependencies or external executables (ie. libexec
-style helpers), but simpler applications often don't need them.
For more complex needs (where data files are involved, or elements of the dependency chain can't be linked in for one reason or another), consider using AppImageKit -- which bundles an application and its dependency chain into a runnable ISO. See docs/links at PortableLinuxApps.org.
In neither of these cases does rpm
or yum
have anything to do with it. It's certainly possible to build an RPM that packages static executables, but that's a matter of changing the %build
section of the spec file such that it passes -static
to gcc, not of doing anything RPM-specific.
To be clear, by the way -- there are compelling reasons why we don't use static libraries all the time!
- Using shared libraries means that applying a security update to a library only means replacing the library itself, not recompiling all applications using it.
- Using shared libraries is more memory-efficient, since the single shared copy of the library in memory can be used by multiple applications.
- Using shared libraries means your executables don't need to include full copies of all the libraries they use, making them much smaller.