如何将处于前沿 linux 的程序编译为旧 linux 上的 运行

How to compile a program on bleeding edge linux to run on old linux

我使用 install Arch Linux 和 duel booted Linux Mint 18.1。在我的大学里,我们安装了 lubuntu 16.04 和 Ubuntu 14.04。我还在 arch Linux 中启用了测试 repos,所以我得到了更新的包,因此当我在 Arch 上编译任何 C++ 程序时,由于版本原因,它不会 运行 在 Linux Mint 上的共享库在 mint 中不匹配。

就像 libMango.so.64 在 arch 中,libMango.so.60 在 mint 中。我怎样才能克服这个问题?

所以我想问一下如何使用较新的编译器和共享库编译任何 C/C++ 以 运行 使用旧的共享库 ?就像我在带有 -m32 标志的 64 位机器上编译 32 位程序一样,是否也有旧共享库的标志?

我正在使用 gcc 8.1。

how can I compile any C/C++ with newer compiler and shared libraries to to run fine with old shared libraries ?

如果这些库的 API (or even the ABI, including size and alignment of internal structures, offsets of fields, vtables 组织发生了不兼容的更改,则您无法 可靠地做到这一点。

一般来说,您最好在另一台计算机上重新编译您的源代码(如果该源代码与您的教育无关,您的大学可能会禁止这样做)。顺便说一句,如果您的源代码位于某些地方 git repository (e.g. github 如果它是开源的)在多台计算机上传输非常容易。

很少有库真正(并记录在案)以 binary 形式(例如在 ABI 级别)与它们的其他版本兼容,但这并不常见. Unix and free software tradition is to care about source level compatibility. And the POSIX 标准只关心源兼容性。

您可以考虑使用一些 chroot-ed environment (see chroot(2) and path_resolution(7) & credentials(7)) to have the essential parts of your older distribution on your newer one. Details are distribution specific (on Debian & Ubuntu, see also schroot and debootstrap)。您还可以考虑 运行 在某些 VM 中进行完整分发,或者使用容器 à la Docker.

您可能会尝试 link(本地)静态地执行您的可执行文件,因此使用 g++ -static

编译并 link