是否有可能编译C / C ++源$ C ​​$ C,在所有的Linux发行版执行无需重新编译? [英] Is it possible to compile a C/C++ source code that executes in all Linux distributions without recompilation?

查看:129
本文介绍了是否有可能编译C / C ++源$ C ​​$ C,在所有的Linux发行版执行无需重新编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以编译C / C ++源$ C ​​$ C,在所有的Linux发行版执行无需重新编译?

Is it possible to compile a C/C++ source code that executes in all Linux distributions without recompilation?

如果答案是肯定的,我可以使用任何外部(非标准的C / C ++)库?

If the answer is yes, can I use any external (non-standard C/C++) libraries?

我想我的分发二进制应用程序,而不是源$ C ​​$ C的分布。

I want distribute my binary application instead of distribute of source code.

推荐答案

没有,你不能编译可执行文件中的所有Linux发行版会执行。但是,您可以编译的,人们往往会最关心的发行工作的可执行文件。

No, you can't compile an executable the executes in all Linux distributions. However, you can compile an executable that works on most distributions that people will tend to care about.


  1. 编译32位。编译为CPU的最低水平你愿意支持。

  1. Compile 32-bit. Compile for the minimum CPU level you're willing to support.

构建自己的glibc的版本。使用 - 使内核选项设置最小的内核版本你愿意支持

Build your own version of glibc. Use the --enable-kernel option to set the minimum kernel version you're willing to support.

编译您打算使用自己所有的其他库。从你的glibc构建和您所选择的CPU /编译器标志使用的标题。

Compile all other libraries you plan to use yourself. Use the headers from your glibc build and your chosen CPU/compiler flags.

静态链接

有关任何你不能链接到静态(例如,如果您需要访问系统的默认名称解析,或者您需要PAM),你要设计自己的助手程序和API。源释放辅助过程,让他们(或安装程序)进行编译。

For anything you couldn't link to statically (for example, if you need access to the system's default name resolution or you need PAM), you have to design your own helper process and API. Release the source to the helper process and let them (or your installer) compile it.

彻底测试在所​​有平台上,你需要支持。

Test thoroughly on all the platforms you need to support.

您可能需要调整一些图书馆,如果他们打电话,不能用这种机制的工作职能。这包括的dlopen 的gethostbyname iconv_open子,等。 (这些类型的功能从根本上依赖于动态链接。请参见上述步骤5,你会得到一个警告,当你链接的这些。)

You may need to tweak some libraries if they call functions that cannot work with this mechanism. That includes dlopen, gethostbyname, iconv_open, and so on. (These kinds of functions fundamentally rely on dynamic linking. See step 5 above. You will get a warning when you link for these.)

此外,时区往往会打破,如果你不小心,因为你的code可能不知道系统的区域格式或区域文件的位置。 (你会得到任何警告这些,它只是将无法工作。)

Also, time zones tend to break if you're not careful because your code may not understand the system's zone format or zone file locations. (You will get no warning for these. It just won't work.)

谁做到这一点大多数人都用最小支持的CPU是一个Pentium 4和最低支持的内核版本是2.6.0建设。

Most people who do this are building with the minimum supported CPU being a Pentium 4 and the minimum supported kernel version being 2.6.0.

这篇关于是否有可能编译C / C ++源$ C ​​$ C,在所有的Linux发行版执行无需重新编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆