简体   繁体   English

如何在linux上运行Linux上运行的程序

[英]How to compile a program on bleeding edge linux to run on old linux

I use install Arch Linux with duel booted Linux Mint 18.1 .In my college we have lubuntu 16.04 and Ubuntu 14.04 installed. 我使用安装Arch Linux与决斗启动的Linux Mint 18.1。在我的大学里我们安装了lubuntu 16.04和Ubuntu 14.04。 I have also enabled testing repos in arch Linux so I get newer packages, thus due to this when I compile any C++ program on Arch it won't run on Linux Mint due to version of shared libraries don't match in mint. 我还在arch Linux中启用了测试repos,所以我得到了更新的软件包,因此当我在Arch上编译任何C ++程序时,由于共享库的版本不匹配而导致它不能在Linux Mint上运行。

like libMango.so.64 is in arch and libMango.so.60 is on mint. 就像libMango.so.64一样,而libMango.so.60也是如此。 How can I overcome with this ? 我怎么能克服这个?

so I am asking for how can I compile any C/C++ with newer compiler and shared libraries to to run fine with old shared libraries ? 所以我要问如何使用较新的编译器和共享库来编译任何C / C ++,以便与旧的共享库一起运行 Just like I compile 32 bit programs on 64 bit machine with -m32 flag , is there flag for old shared libraries too ? 就像我在带有-m32标志的64位机器上编译32位程序一样,旧共享库也有标志吗?

I am using gcc 8.1. 我正在使用gcc 8.1。

how can I compile any C/C++ with newer compiler and shared libraries to to run fine with old shared libraries ? 如何使用较新的编译器和共享库编译任何C / C ++,以便与旧的共享库一起运行?

You cannot do that reliably if the API (or even the ABI , including size and alignment of internal structures, offsets of fields, vtables organization) of those libraries have changed incompatibly. 如果这些库的API (甚至是ABI ,包括内部结构的大小和对齐,字段的偏移, vtables组织)发生了不兼容的变化那么你就无法可靠地做到这一点

In general, you'll better recompile your source code on the other computer (and your college might forbid that, if that source is unrelated to your education). 通常,您最好在另一台计算机上重新编译源代码 (如果该源与您的教育无关,您的大学可能会禁止该源代码)。 BTW, if your source code sits in some git repository (eg github if it is open source) transferring on multiple computers is very easy. 顺便说一句,如果您的源代码位于某个git存储库(例如,如果它是开源的github),那么在多台计算机上进行传输非常容易。

Some very few libraries make genuine (and documented) efforts on being compatible with other versions of them in binary form (eg at the ABI level), but this is not usual. 一些极少数的库会以二进制形式(例如在ABI级别)与其他版本的库兼容而进行真正(和记录)的努力,但这并不常见。 The Unix and free software tradition is to care about source level compatibility. Unix自由软件的传统是关心源代码级兼容性。 And the POSIX standard cares only about source compatibility. POSIX标准仅关注源兼容性。

You might consider using some 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. 您可以考虑使用一些chroot -ed环境(请参阅chroot(2)path_resolution(7)credentials(7) )将旧版本的基本部分放在较新的版本上。 Details are distribution specific (on Debian & Ubuntu, see also schroot and debootstrap ). 详细信息是特定于分发的(在Debian和Ubuntu上,另见schrootdebootstrap )。 You could also consider running a full distribution in some VM, or using containers à la Docker. 您还可以考虑在某个VM中运行完整分发,或使用Docker中的容器。

And you might try to link (locally) your executable statically, so compile and link with g++ -static 您可能会尝试静态链接(本地)您的可执行文件,因此编译并链接到g++ -static

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM