首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在一个Linux发行版上使用g++编译的可执行文件在另一个Linux发行版上使用有限制吗?

在一个Linux发行版上使用g++编译的可执行文件在另一个Linux发行版上使用有限制吗?
EN

Stack Overflow用户
提问于 2012-10-19 23:18:54
回答 4查看 365关注 0票数 8

在不同发行版之间有没有什么特性或变化会影响在一个发行版上使用GCC 4.7.x编译的C++二进制文件在另一个发行版上直接使用?我理解理想的情况是在第二个发行版上从源代码编译,但我真的不愿意担心在我的生产机器上编译新的GCC版本和程序源代码。我是一个相对缺乏经验的linux用户(因此才有这个问题!)相对于命令行编译,我仍然更喜欢IDE,ssh是我真正能用来访问生产机器的唯一工具。

代码本身并不有趣,但它确实利用了mill操作系统的一些功能,如阻塞、套接字等。

任何建议都将不胜感激!

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-10-19 23:35:12

除非二进制文件构建在完全相同的操作系统(包括版本)的上,并且完全相同的硬件,否则没有保证。

在实践中:

  1. 如果硬件与芯片系列相同,则应该可以工作。

代码语言:javascript
复制
- This is because most people don't turn on the hardware specific optimizations (but they can).
- Moving binaries across chip sets is highly unlikely to work 
- Moving binaries from older to newer members of a hardware family is likely to work
- Moving binaries from newer to older members of a hardware family is less likely (but will depend on optimization and compiler settings (ir moving from 64 to 32 bit architecture is unlikely to work).

  1. 如果操作系统有相同的主机号,那么它(可能)应该可以工作。

代码语言:javascript
复制
- The version of OS that a binary will work across will depend on the version of the compiler used to build it and the host OS.
- If the compiler has changes in the ABI it generates then all bets are off. But usually a change in the ABI generated by the compiler will be a major issue and thus only happen at major points in the OS road map (not at minor increments).

  1. 我的建议是从源代码构建的。

代码语言:javascript
复制
- Don't specifically go out and update the development environment (use the one that comes with distribution (if you do the default updates they will not break backwards compatibility)).
- Building is easy just read the `README` file. But usually it involves running two commands `./configure` and `make`. If you don't want anything special you usually do not need to do anything else.

票数 5
EN

Stack Overflow用户

发布于 2012-10-19 23:29:58

G++有一个稳定的ABI已经有很长一段时间了,所以这应该不会造成问题。可能导致问题的是使用动态链接库。运行该程序的系统将需要具有编译可执行文件所依据的任何共享库的兼容版本。如果只使用静态链接,应该不会有问题。您可以使用-static选项打开静态链接。

票数 3
EN

Stack Overflow用户

发布于 2012-10-19 23:31:48

使用静态链接时,必须满足两个条件:

1)目标系统和构建系统必须具有相同的体系结构(有例外:您可以在多个64位主机上运行32位二进制文件)

2)目标系统上的(g)libc包的版本不能比构建系统上的旧(您有时可以通过较小的版本差异逃脱惩罚)

随着动态链接的出现,它变得更加复杂。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12977381

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档